Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Construct a REGEX by selected substitution

by jeanluca (Deacon)
on Sep 29, 2007 at 08:11 UTC ( [id://641673]=note: print w/replies, xml ) Need Help??


in reply to Construct a REGEX by selected substitution

Have a look at perlre which helps me all the time!
Especially the part Extended Patterns (which I've used here) is very interesting!

For the string you submitted the following will do
$str =~ s/(?<=\s)TXT/FOO/g ;
CHeers
LuCa

UPDATE: this one might be easier
$str =~ s/ TXT/ FOO/g ;

Replies are listed 'Best First'.
Re^2: Construct a REGEX by selected substitution
by pysome (Scribe) on Sep 29, 2007 at 08:37 UTC
    How to deal if the $str is :
    '<a code=" TXT"> abc =" TXT </a> <text code= TXT> efg =" TXT </text> < +input s=" TXT"> hig =" TXT</input>';
    Thanks,

      It looks like what you really need to do is parse some HTML and manipulate some of the elements of the parsed text. However it's not clear just what you want to be able to manipulate, particularly as the sample you've given isn't a well formed fragment of HTML - you seem to have mismatched quote characters. It doesn't help that it's not clear just which TXT instances in the sample ought to be replaced.

      For modest sized documents HTML::TreeParser may be the most appropriate tool for the job.


      Perl is environmentally friendly - it saves trees
      Did you read the perlre documentation ? It contains the answer to your question!
      Show us what you've tried or tell us whats unclear about the documentation!

      LuCa

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-18 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found