Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Hazardous characters filter

by no_slogan (Deacon)
on Mar 24, 2014 at 18:41 UTC ( [id://1079578]=note: print w/replies, xml ) Need Help??


in reply to Hazardous characters filter

How about:

s/(<url>)|<|>/$1||''/eg

Also, note that by modifying $_[0], you're also changing $test. And may I ask in what context < and > are "hazardous"?

Replies are listed 'Best First'.
Re^2: Hazardous characters filter
by Anonymous Monk on Mar 24, 2014 at 18:51 UTC
    This
    s/(<url>)|<|>/$1||''/eg
    and this $_[0] =~ s/<|>//g
    will replace the "<" and ">", but what I am trying to do is to replace "<" and ">" only if this pattern "<url>" is not found on the string. At the end the string should be:

    From this: "This is not ok < but this is ok <url>".
    To: "This is not ok but this is ok <url>".

    Thanks!

      what I am trying to do is to replace "<" and ">" only if this pattern "<url>" is not found on the string. At the end the string should be:

      From this: "This is not ok < but this is ok <url>".

      To: "This is not ok but this is ok <url>".

      There is a contradiction between your description of what you want and the example you provide: in the example, the "<url>" pattern is found and, according to your stated rules, no substitution whatsoever should occur. It seems that your example probably makes clearer what you want, but you are failing to describe your needs correctly in plain English words. If you can't explain it in literary language, then you probably don't really understand what you are trying to do. And this might be the key to your problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1079578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (1)
As of 2024-04-19 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found