J86
J86

Reputation: 15237

Complex RegEx Find Replace in Sublime Text

I have a massive JSON file and inside it, there is a lot of this:

"Description":"<br><br><br> <table border=\"1\" padding=\"0\"> <tr><td>CCGcode</td><td>00G</td></tr> <tr><td>CCGname</td><td>NHS Newcastle North and East CCG</td></tr>"
"Description":"<br><br><br> <table border=\"1\" padding=\"0\"> <tr><td>CCGcode</td><td>00J</td></tr> <tr><td>CCGname</td><td>NHS North Durham CCG</td></tr>"

The above is surrounded with a lot of other stuff, similiar to this. I would like to replace any such occurrences with:

"Description":"NHS Newcastle North and East CCG"
"Description":"NHS North Durham CCG"

But I do not know how to. I've tried multiple Regular Expressions, but couldn't get it to work.

Upvotes: 0

Views: 396

Answers (2)

Avinash Raj
Avinash Raj

Reputation: 174706

Use capturing groups to capture the text you want for later use.

Regex:

^("Description":").*<td>([^<>\n]*).*$

OR

^("Description":").*?<td>CCGname<\/td><td>([^<>\n]*).*$

Replacement string:

$1$2"

DEMO

Upvotes: 1

Bohemian
Bohemian

Reputation: 425033

If your tool supports look behinds:

(?<="Description":").*?CCGname</td><td>(.*?)<.*

Replace with $1

Upvotes: 0

Related Questions