in reply to Re: Splitting on unusual regex
in thread Splitting on unusual regex

Yeah, you're right that I should abandon split and this nearly works-- the one thing (which may have been unclear above) is that I'd like it to ignore escaped parentheses, so that
( some stuff\) )
is not split up. I'm working on a variation that ignores \) and \( and will fit into my code like this:
for ($script =~ m[( (?: \( [^)] + \) ) | \S+)]gx) { push @script, $_; }

~dewey

Replies are listed 'Best First'.
Re^3: Splitting on unusual regex
by BrowserUk (Patriarch) on May 14, 2007 at 06:58 UTC

    Something like this?

    #! perl -slw use strict; my $code = <<EOC; This is some JOY code This is (some more) JOY code And this is some JOY code with escaped \\( and \\) like (this \\) and \\(this) and \\) EOC print for $code =~ m[ ( (?: \( (?: \\[()] | [^()] )+ \) ) | \S+ ) ]gx; __END__ C:\test>615217 This is some JOY code This is (some more) JOY code And this is some JOY code with escaped \( and \) like (this \) and \(this) and \)

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Exactly... man, I'm really going to have to resist the urge to put all my questions on here or I'll never write any of my code myself! Thanks a lot guys, I'm slowly improving at regular expressions.

      ~dewey