> -----Original Message-----
> From: Kris Vermeulen [mailto:[EMAIL PROTECTED]]
> Sent: Monday, November 26, 2001 11:26 AM
> To: [EMAIL PROTECTED]
> Subject: regular expressions and search and replace.
> 
> 
> Hi everyone!
> 
> Many programming languages are taking over regular expressions.
> But since it originated from Perl (am I correct?), I taught this
> would be the ideal place to drop my beginner's question.
> 
> I already succeeded in replacing occurrences of some string in a
> complete text, but is it also possible to replace a beginning piece
> and an ending piece of string and just leave the text in between?
> I'll give a quick example. 
> 
> If I have a string:
> "some text [LINK='page.html']linkname[/LINK] some more text"
> 
> I want to replace every "[LINK='page.html']" with <a href='page.html'>
> I just want to search for [LINK= and the matching ] and just leave
> the text in between. Is this possible using just regular expressions?

The general idea is to match text in capturing parens and then
refer to that text using $1, $2, etc. in the replacement expression:

   s/X(.*)X/Y$1Y/;    # changes "Xfoo barX" to "Yfoo barY"

perldoc perlre (search for "backreference") for all the poop.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to