in reply to codem/(?:-x pattern) #comment /x bug?/code

First, your join statement on @br is useless as @br only contains one element.

Second, when you have a regex using a (?:...) modifier, anything between the question mark and colon acts as a local switch unless it's after a -, in which case, it serves to negate a switch that's been applied to the entire regex. In this case, the /x switch (or modifier, if you prefer) at the end of the regex has the regex ignore unescaped whitespace, which you don't have in your first regex. As a result, your /x switch serves no purpose in this regex, and would be negated by the ?-x: construct, in any event.

The reason why the second regex does not match is because it's trying to match "#commenthere" (note the lack of spaces). Since they don't appear in your target text, you get no match.

Hope this helps.

Cheers,
Ovid

Update: I'm a moron. I need to think about this one a bit more. It's a lot trickier than I first thought. Now that I have a better idea of what you are doing, this does look like a bug. Changing ?-x: to ?: makes it work, but (?-x:...) is supposed to be local.

P.S. I am using 5.005 (ActiveState on WinNT)

  • Comment on (Ovid) Re: codem/(?:-x pattern) #comment /x bug?/code

Replies are listed 'Best First'.
RE: (Ovid) Re: codem/(?:-x pattern) #comment /x bug?/code
by dcorbin (Sexton) on Sep 08, 2000 at 00:11 UTC

    1) I know. It's code that's been simplified to show the problem.

    2) That's what I thought. I know that /x is not relevant in the first case, but I was trying to show two very consistent cases, one of which works and one doesn't when I think they both should.

    3) But the regex is applied with the x modifier at the expression level. Doesn't that mean that the comment should be treated as a comment?