Question

I have multiple <li> in my code, well over 3,000 of them (don't ask!).

They are all either in the format:

<li>Name, Job, Company</li>

or

<li>Job, Company</li>

I need to find the ones that contain a Name (i.e. the ones with two commas ,, as opposed to just one), and remove the names. I was hoping to use Sublime Text's Regex find+replace feature.

Now, I can select all the lines that contain two commas using the following regex:

<li>.*,.*,.*</li>

But how do I now replace those with just the second and third .*s, discarding the first?

Was it helpful?

Solution

find this :

<li>.*,(.*),(.*)</li>

replace with :

<li>\1,\2</li>

or

<li>$1,$2</li>

whatever your editor supports

OTHER TIPS

sed -r 's/[^,]*,([^,]*,[^,]*)/\1/g'

not .* because it would match the comma.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top