-2

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?

Robert
  • 3
  • 2
  • 2
    Don't parse HTML with regex, use a proper XML/HTML parser. Check: [Using regular expressions with HTML tags](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) You can use one of the following : xmllint xmlstarlet saxon-lint – Gilles Quénot Feb 27 '18 at 12:11

1 Answers1

0

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

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

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

and your replace

\1\2">\2&lt/a>

\1 matches everything before the ">

\2 matches your 10 digit number

jcaponi
  • 389
  • 2
  • 10