Regular Expressions Cookbook, 2nd Edition
by Steven Levithan
Published by
O'Reilly Media, Inc., 2012
and
Tags
| Replacement text flavors: .NET, JavaScript, Perl |
<a●href="$0">$0</a>| Replacement text flavors: .NET, Java, XRegExp, PHP |
<a●href="\0">\0</a>| Replacement text flavors: PHP, Ruby |
<a●href="\&">\&</a>| Replacement text flavor: Ruby |
<a●href="\g<0>">\g<0></a>| Replacement text flavor: Python |
When programming, you can implement this search-and-replace as explained in Recipe 3.15.
The solution to this problem is very straightforward. We use a
regular expression to match a URL, and then replace it with «<a●href="»,
where URL">URL</a>URL represents the URL that we matched.
Different programming languages use different syntax for the replacement
text, hence the long list of solutions to this problem. But they all do
exactly the same thing. Recipe 2.20
explains the replacement text syntax.
Recipes 8.2 or 8.4 explain the regular expressions to be used along with these replacement texts.
Techniques used in the replacement text in this recipe are discussed in Chapter 2. Recipe 2.21 explains how to insert text matched by capturing groups into the replacement text.
When programming, you can implement this search-and-replace as explained in Recipe 3.15.