Rod
Rod

Reputation: 15477

Search and Replace with Regular Expression

I have the following HTML snippet and there's a bunch more divs on the page. I'd like to surround all labels (Name, Current Position and Birth Place in this case) with strong tags. I can't use css in this case.

So I was thinking would a regular expression work in this case? More specifically, I'd like to use Visual Studio Search and Replace with Regular Expressions option to do this. So find all data to left of colon and replace value with <strong>value found</strong>

<div class="col-6">
    Name:<br/>blah
</div>

<div class="col-6">
    Current Position:<br/>blah
</div>

<div class="col-6">
    Birth Place:<br/>blah
</div>

Upvotes: 1

Views: 69

Answers (2)

Brian Stephens
Brian Stephens

Reputation: 5271

In the search tool, just find this:

([a-z ])+:

and replace with this:

<strong>$1</strong>:

Note: the VS search & replace is not case-sensitive by default

Upvotes: 2

fejese
fejese

Reputation: 4628

You then want to search for a beginning of the line (^) followed by white space (\s*) then some non-line break and non-colon ([^:\n]) followed by a colon and surround the second capture group with the <strong> tag.

Search:

^(\s*)([^:\n]+:)

Replace:

\1<strong>\2</strong>

See this fiddle for more details: http://regex101.com/r/xB8tD5/2

Upvotes: 1

Related Questions