in reply to Re: A question on splitting
in thread A question on splitting

So, let me see if I can understand your regexg.

Split on "," if (0 or 1 occurances) (?) and if there is NOT (!) a space after ( ).

So, if I wanted to check for 1 or more spaces, would this be correct ?

split /,(?! +)/, $str

Replies are listed 'Best First'.
Re: A question on splitting
by Abigail-II (Bishop) on Jan 14, 2004 at 21:17 UTC
    There's no need to check for more than one space. If a comma is followed by say 5 spaces, it's also followed by a space. There's only one character relevant here, and that's the character right after the comma.

    Abigail

Re: Re: Re: A question on splitting
by ysth (Canon) on Jan 14, 2004 at 22:14 UTC
    Not quite. (?!pattern) is a special assertion that says the regex should only succeed if pattern would not match at that point (see perlre). So the regex has two parts: , (comma) and (?! ) (not followed by a space).

    Note that (?! ) (or it's positive counterpart (?= )) do not consume any part of the string. So /a(?=0)\d{2}/ applied to "a012" will match just "a01".

    Changing it to have a + doesn't affect anything, since if it has more than one space after the comma, it definitely has one space.