[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: [LI] search and replace using Regular Expressions



On Wed, Jan 05, 2000 at 06:39:42PM +0530, Anand Raman wrote:

> To the end of each of these lines i want to append a </a> tag .. 
> 
> <li> <a href="http://metalab.unc.edu/javafaq/mailinglists.html";>    Java Mailing Lists
> <li> <a href="http://www.mindspring.com/~scdrye/java/faq.html";>     THE SWING/JFC FAQ
> <li> <a href="http://java.sun.com/products/jdbc/faq.html";>          JDBC(TM) Technology -
> 
> I tried doing this in vi editor and the following regular expression matches the whole line 
> /^[a-z<>A-Z0-9/:."'=~()?\-&%# ]*
> 
> However when i try to append the contents using the following 
> :%s/\(^[a-z<>A-Z0-9/:."'=~()?\-&%# ]*\)/\1<\/a>/gc
> it fails

First things first: you dont have a closing \) there.

Secondly, your character class has almost all printable chars
there.  If that's what you intended, use .* instead of
[allthatstuff]*.

Lastly, to append a fixed string to any lines in vi:
    :%s/$/<\/a>/g
No need to bother with what the line actually has if you don't
really care.

Hope this helps.  Any more regex problems feel free to ask.
--------------------------------------------------------------------
The Linux India Mailing List Archives are now available.  Please search
the archive at http://lists.linux-india.org/ before posting your question
to avoid repetition and save bandwidth.