Using Sublime Text 2, I want to use regex to replace every href value between " and " with a new value.
Example:
<a href="link/to/somewhere.html">
convert to
<a href="#">
But the href has to have a corresponding <a>
tag not within a <link>
tag.
You can use the following. Use Ctrl + H to open the Search and Replace, enable Regular Expression
Find: (<a[^>]*href=")[^"]*("[^>]*>)
Replace: $1#$2
Alternatively, you can use the \K
escape sequence which is little more simpler. \K
resets the starting point of the reported match and any previously consumed characters are no longer included.
Find: <a[^>]*href="\K[^"]*
Replace: #
In Sublime Text 2:
Find What: <a (.+ )?href="([^"]+)"([^>]+)?>
Replace With: <a \1href="#"\3>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With