Computer Hope

Software => BSD, Linux, and Unix => Topic started by: rynjax on November 30, 2010, 08:35:41 AM

Title: regex search and replace - red yellow purple
Post by: rynjax on November 30, 2010, 08:35:41 AM
Hi everyone,

I have used regex before but I am trying to do something new with it, and I don't even know a word to describe it, so I'm just going to try to explain.

I am using SciTE text editor under Ubuntu Jaunty, and the text editor has a regex search & replace feature.

I want to search through a document where there are words surrounded by bold html tags like this:
RED

YELLOW

PURPLE


I want to replace the first bold tag with a hyperlink which includes the actual word itself but in all lowercase letters. So, in order for this to happen, regex has got to be able to "read ahead" and find out what word is between the bold html tags, before anything gets replaced. Is this possible? Here is what I want my result to look like, after the search/replace finishes:

<a href="red.html">RED[/url]

<a href="yellow.html">YELLOW[/url]

<a href="purple.html">PURPLE[/url]


So I am asking 3 things:
(1) is this possible when using regex?
(2) what is it called (the "reading ahead" part)? i want to be more intelligent about the terminology!
(3) can you either show me how, or point me to a tutorial which is in fairly simple language?

Thank you very much.
rynjax