Handy Regular Expressions
Posted April 1st, 2009 by Eric WebbWhile working on a Sharepoint css file, I was able to use a nift regex instead of copying and pasting all over the place.
The tag I had looked like this:
#MSOZoneCell_WebPartWPQ4 td h3 a
I wanted to add a tag on the end so that it looked like this:
#MSOZoneCell_WebPartWPQ4 td h3 a, #MSOZoneCell_WebPartWPQ5 td h3 a
I used this Regex in Sharepoint Designer to do so:
Find
#MSOZoneCell_WebPartWPQ4 {.*$}
Replace
#MSOZoneCell_WebPartWPQ4 \1, #MSOZoneCell_WebPartWPQ5 \1
The “\1″ is called a “Tagged Expression”. It refers to the part of the value that is tagged in the “Find” syntax. You tag something using brackets, so in this case “.*$” was tagged, which corresponded to this part of the result ” td h3 a”. I had about 10 of these, so this saved me a lot of time.
Leave a Reply