in reply to Capturing everything after an optional character in a regex?

perl -le '$string="abcX123"; $string =~ /X([^\s]+)/; print $1;' 123

Update 2003-12-04 12:50:48 CET: See saouq's node in this thread for a solution which fills all of Anonymous Monk's requirements, as mentioned in opqdonut's post below.

--
Allolex

Replies are listed 'Best First'.
Re: Re: Capturing everything after an optional character in a regex?
by opqdonut (Acolyte) on Dec 04, 2003 at 11:32 UTC

    Allolex, your piece o' code doesn't really satisfy the needs of Anonymous Monk, he needed to capture the whole line if there is no X.

    saouq's code is simply beautiful, maybe someday my code will look like that :)

    apparently yours,
    J

      Well, it meets the original requirements as I understood them. See my previous reply to saouq's node for part of the reason (besides laziness and stupidity on my part)---It's nice to see that I'm not the only one who doesn't read the whole thread before posting ;) For the record, davido /msg'd me concerning this about three seconds after I hit 'create'... Even at past 2 a.m. his time, he was more alert than me.

      --
      Allolex

        Well, it meets the original requirements as I understood them.

        And you shouldn't fault yourself either. You can't be expected to understand the requirements any better than they are communicated. In this case, they were very poorly communicated. For that matter, we still haven't been given enough information to answer this with confidence. I have asked for a restatement. We'll see if we get one.

        -sauoq
        "My two cents aren't worth a dime.";