Using Grep and BBEdit/Textwrangler to copy a set variable and paste it earlier in the line

628 views Asked by At

I have a long HTML document with a list of 10-digit text variables that I'd like to copy and paste into a link earlier in the line, for example:

<a href="example.com/">1234567890</a>

Into:

<a href="example.com/1234567890">1234567890</a>

So, a Grep pattern that finds the 10-digit variable, then copies and pastes it either 2 characters before it, or identifies the incomplete href and pastes it at the end of it.

Any ideas?

1

There are 1 answers

1
jcaponi On BEST ANSWER

Is your input data always that consistent? (link/number/closing link)?

In that case, your 'find' can be (in textwrangler's syntax)

(.*)">(\d{10})</a>

and your replace

\1\2">\2</a>

\1 matches everything before the ">

\2 matches your 10 digit number