simple regex not so simple (perl)
Hi all,
I am having trouble with a substitution regex. I have a string where I need all occurrences of certain string replaced with another. ie replace all [cor] with <font color="red"> At the moment I have this: Code:
$search_string = '[cor]'; Code:
some normal text I get these results: Code:
its automatically escaping all the characters I need! How can I get around this? I've been trying for days! If I escape the < "> characters before I perform the regex, I just get multiple escape characters! p.s. the \Q and \E modifiers quote whats in the string and it seems to go ok, so thats not the problem I don't think. confused: |
Sorry, I'm not much of a PERL hacker,
but, if you can open the file in vi (or vim), like this: vi filename then enter the following (just copy and paste) :1,$s/\[cor\]/<font color="red">/g and press <RETURN> seems to work for me. Hope this helps. |
Hi thanks for the reply,
but its a CGI script that I am building that will get a bunch of search expressions from an array and replace them with the equivalent html, so its got to be automated. (although the example I gave was a static one, I'll extend it when i get it going!) Cheers though! |
Can you try:
$replace_string = '\'<font color="red">\''; or $replace_string = "'<font color=\"red\">'"; ? |
I may be misunderstanding the question, but can you not use something like this?
perl -pi -e 's/[c]/<font color=\"red\">/g' $FILENAME That should replease every occurence of [c] with <font color="red"> Sorry if i have misunderstood the problem. -farmerjoe |
thanks for the reply also, I just got it actually.
Code:
$search_string = "[cor]"; |
All times are GMT -5. The time now is 05:43 AM. |