Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Stuck in komplexer regex, at least for me

by ultibuzz (Monk)
on Mar 26, 2007 at 19:17 UTC ( #606641=note: print w/replies, xml ) Need Help??

in reply to Stuck in komplexer regex, at least for me

sorry for the bad explanation, i try to explain it better
the following regex will produce this

s/(?<=\d{2})0*(?<=\d{4})0+// output 215000007801 -> 2157801 300000324002 -> 30324002 890000457651 -> 89457651 210004563401 -> 214563401 201045139158 -> 201045139158

these 2 outputs are wrong
201045139158 -> 201045139158
215000007801 -> 2157801
shoud be
215000007801 -> 21507801
201045139158 -> 20145139158

now i try to explain the rule better,counting starts at 0
the 0 , 1 digits shoud be untouched
if the 2 digit is a 0 and the next digit is a 0 remove all 0 untill first non 0
if the 2 digit a 0 and the next is a non 0 remove the 0
if the 3 digit is a 0 and follows by a 0 then remove all 0 except the 0 at 3 digit
if the 3 digit is a 0 and the next digit is a non 0 remove only the 0
if the 4 digit is a 0 remove it and all following 0 untill non 0

i hope that makes it a bit clearer, i know its kinda confusing

kd ultibuzz

i will test the help u all already given tomorrow at office,thx alot

Replies are listed 'Best First'.
Re^2: Stuck in komplexer regex, at least for me
by xicheng (Sexton) on Mar 26, 2007 at 23:05 UTC
    Hi, You need an anchor '^' to make sure the matchings start from the beginning of your strings..and your requirements might be written into two patterns which would be much easier to understand(the order of two s/// expressions matters)..
    use warnings;
    use strict;
    while(<DATA>) {

      your right 2 patterns look easyer,

      i am testing atm 5 million numbers and afterwards they will check with the system, then i know if all fit are some fail.

      same testing atm for the regex fanboy pattern ;)

      thx alot for the quick and very good help
      kd ultibuzz

      UPDATE:there is a problem with numbers like

      they shoud change into
      but they remained unchanged

      UPDATE 2:i have it running with an if loop, if digit 2 or 3 is 0 use new pattern else my old one ^^
      this isn't nice at all and i don't like it ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606641]
[Corion]: ... or so I think. As I said, I'm somewhat vague on how to make AnyEvent cooperate with a callback-driven IO event loop that gives me callbacks when data is available or can be written
[ambrus]: what push_write thing? I don't think you need that. that's implemented generically by AnyEvent::Handle
[Corion]: ambrus: Yeah, that's what I think as well. But you give me an idea, maybe I should start with implementing the timer, as that should be far simpler and with fewer edge-cases/nasty interaction than the file watcher
[ambrus]: You only provide the watcher part that tells when the handle is readable or writable, not the actual writing and reading.
[Corion]: ambrus: Hmmm. It makes sense that AnyEvent would implement the push_write itself, but I think I don't have a good idea of where the boundary between AnyEvent and the underlying event system lies... Implementing the timer should give me a better idea
[ambrus]: Corion: push_write is in the higher level abstraction of AnyEvent::Handle, not in the watcher
[Corion]: ambrus: Hmm - rereading Prima::File, that merrily coincides with what Prima does - it tells you "you can read", and you're supposed to read from the fh yourself. I thought it called you with the data already read, which would've been harder to integrate
[ambrus]: you just need an io watcher, created by &AnyEvent::Impl:: Whatever::io(...)
[Corion]: So after talking it through with you even while I'm still not entirely clear on where AE ends and my implementation begins, I think I understand that I only need to implement some smaller parts for each functionality I want to support.
[Corion]: Yeah... and you might even be able to mix and match additional functionality if you have additional async suppliers, like from a separate thread

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2016-12-08 12:21 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (141 votes). Check out past polls.