Search code examples
htmlgreptextwranglerbbedit

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


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?


Solution

  • 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