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

my substitution problem:

by Madams (Monk)
on Feb 13, 2001 at 07:35 UTC ( #58069=perlquestion: print w/ replies, xml ) Need Help??
Madams has asked for the wisdom of the Perl Monks concerning the following question:

I have a string,and a substitution:
'11+b^10+s'=~s/(?<!\^)(?:\d+\+)//g;
it should result in:
   'b^10+s' NOT 'b^1s' !
it works if the number to the right of the "^" is less than 10 but not if greater.
i want to strip all numbers followed by a "+" (including the "+") but NOT if they are preceeded by a "^".

what should i do? (regexi drive mike crazy...(is that the proper plural?)

Comment on my substitution problem:
Select or Download Code
Re (tilly) 1: my substitution problem:
by tilly (Archbishop) on Feb 13, 2001 at 07:49 UTC
    Regexen problems? Well the rule is that it will work really really hard to find a match. So figure out why it is finding the unwanted match and deny it.

    Well on the second substitution it is clearly able to match "0+" after a 1. Well does that fit the rule? Why yes, the preceeding "1" is not "^", so it can match What to do? Why deny it a digit there. That gives us:

    s/(?<![\^\d])(?:\d+\+)//g; # ^^^^^^ <- was just \^ before
    which does what you asked.
      Hey tilly!
      thanks (for the fix and the plural i LIKE regexen as a word), i think i was getting google eyed trying to figure that out.. i was relatively sure it involved my not specifying the negassert correctly but i just continually woofed it! regexen are one way to kill your eyesight ;)

      after a while they look like /{][P)(*^8(*(/ over and over :)
      p.s. still like the multfor "loop" you clued me in on (still studying it cause it's a cool hack!)

      Mucho gracias!
      madams.
OGRE strikes again! Re: my substitution problem:
by japhy (Canon) on Feb 13, 2001 at 20:00 UTC
    In an effort to shamelessly plug my modules, I produce the output of the OGRE:
    NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- (?<! look behind to see if there is not: ---------------------------------------------------------------------- \^ '^' ---------------------------------------------------------------------- ) end of look-behind ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \+ '+' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
    As tilly pointed out, the problem is that in the string "^123", "123" isn't a valid match, but "23" is.

    japhy -- Perl and Regex Hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://58069]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-07-26 09:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls