in reply to automagic-HTML regex

Your problem is in the very first line of that regex. The dollar in ^\[$ does not match a newline. It matches right before the newline. So, that newline goes into your $1 captured by (.*) with the /s modifier. In your second substitution (the one in the eval'd part of the first one), that caret (^) will match the begining of the first line in $1 which, in your case, contains a single newline.

You can fix it by telling your regex to match an opening brace and then match as much whitespace as possible. Try changing ^\[$ to ^\[\s*.

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

Replies are listed 'Best First'.
Re: Re: automagic-HTML regex
by Enlil (Parson) on Jun 16, 2003 at 22:54 UTC
    Try changing ^\[$ to ^\[\s*.

    I don't know if the following is valid:

    $string = ' [foobar] [ this is a list of things that are in a list ] blah blah later after-list text ';
    but my guess is that if it is valid then i doubt the change sauoq suggested will return the wanted results. what you probably want is to change ^\[$ to ^\[\s*?\n (where then the [ can only be followed by "optional whitespace" and then a newline.)

    -enlil