Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: Skipping special tags in regexes

by flounder99 (Friar)
on Dec 04, 2003 at 18:40 UTC ( [id://312274]=note: print w/replies, xml ) Need Help??


in reply to Re: Skipping special tags in regexes
in thread Skipping special tags in regexes

Is there a reason you are using the /(??{ })/ code block other than just to make a more general solution? This seems to work just fine.
#!/usr/bin/perl use strict; use warnings; my $tag = '(?:<[^>]*>)'; while (<DATA>) { s/($tag*tacos)/yummy $1/g; s/($tag*salad)/green $1/g; print; } __DATA__ I like tacos. <5b>I <5c>like <5d>tacos. I like a salad. <foo>I <foo>like <foo>a <bar><baz><foo>salad. <foo>I <foo>like <foo>a <bar><baz><foo>salad <bup>with <bobob>tacos. I like yummy tacos. <5b>I <5c>like yummy <5d>tacos. I like a green salad. <foo>I <foo>like <foo>a green <bar><baz><foo>salad. <foo>I <foo>like <foo>a green <bar><baz><foo>salad <bup>with yummy <bo +bob>tacos.

--

flounder

Replies are listed 'Best First'.
Re: Skipping special tags in regexes
by Abigail-II (Bishop) on Dec 04, 2003 at 22:23 UTC
    Is there a reason you are using the /(??{ })/ code block other than just to make a more general solution?
    Because I was expecting the OP to refine his question, and come up with a slightly different definition of a "word" (perhaps it needed trailing tags as well, or not more than 2 tags, whatever). Then I only need to change the sub, and not every regex using it.

    I think my solution is more general than yours, but the effect is the same.

    Abigail

      I assumed you were shooting for generality. I just wanted to know if there was a technical reason I was missing.

      --

      flounder

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found