It will match any word (containing letters or numbers) with at least one underscore, and replace it with your linkOn *nix: perl -pi -e 's{\b((?:[a-zA-Z0-9]+_)+[a-zA-Z0-9])+\(\)\b}{<a href=" +$1.html">$1()</a>}g' * On Windows (I think): perl -pi -e "s{\b((?:[a-zA-Z0-9]+_)+[a-zA-Z0-9]+\(\)\b}{<a href=\" +$1.html\">$1()</a>}g" *
Explanation
s{ # match and replace on $_ \b # start with a word boundary ( # capture the matches and store in + $1 (?:[a-zA-Z0-9]+_)+ # letters and numbers followed by +_ at least once [a-zA-Z0-9]+ # must end with letters/numbers ) \(\) # then () \b # followed by word boundary } { <a href="$1.html">$1()</a> # replace the matched text with th +is string } # substituting the value of $1 (th +e first capture) g # perform this replace on all matc +hes in $_
Result
Clintabc abc() abc_ abc_() abc_def abc_def() abc_def_ abc_def_() abc_def_ghi abc_def_ghi() BECOMES: abc abc() abc_ abc_() <a href="abc_def.html">abc_def()</a> <a href="abc_def.html">abc_def()</a>() abc_def_ abc_def_() <a href="abc_def_ghi.html">abc_def_ghi()</a> <a href="abc_def_ghi.html">abc_def_ghi()</a>()
Update: missed the requirement that the original string should end with ()
In reply to Re: Edit html files in directory
by clinton
in thread Edit html files in directory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |