Regular expression error

ericnormand wrote on Thursday, May 12, 2005:

I’m getting errors that look like they have to do with the \ character in regular expressions.  The two I have encountered so far are openemr/interface/main/myadmin/libraries/common.lib.php line 1082
and
openemr/interface/main/myadmin/main.php line 246

Is there a setting I’m missing, because these don’t seem to be bugs that could be passed up.

Eric

sunsetsystems wrote on Thursday, May 12, 2005:

What version of PHP, and where did the PHP build come from?  It does smell a bit like a PHP bug or build problem.

I think Perl-compatible regex’s are more popular.  You could try converting to those if you understand what’s going on.

– Rod <rod at sunsetsystems dot com>

ericnormand wrote on Saturday, May 14, 2005:

It’s php version 4.3.10-2 built for debian.

sunsetsystems wrote on Sunday, May 15, 2005:

Looking at http://www.php.net/manual/en/ref.regex.php, the second “warning” is curious.  It’s as if there are different ways you can build regular expression support and they are not compatible with each other.

Just a thought.  I guess what I’d do is play with the regex’s.

– Rod <rod at sunsetsystems dot com>

ericnormand wrote on Monday, May 16, 2005:

I played with the one that gave me the error message and it seemed to work, but another one had a problem.  That’s why the problem seemed more general.  I wouldn’t mind playing with the regex’s, I just don’t know what they are supposed to be matching specifically – I’m afraid of guessing what the regex is trying to do.  Basically with the first one I just made the slash into a triple slash, so it went from
“^|[^\]” to “^|[^\\\]”.  But this doesn’t really seem to make much sense as a matcher.  Why put the ^ outside the brackets?

I’m also afraid to mess with php regex settings because I have other programs running that are working.

Thanks
Eric

ericnormand wrote on Monday, May 16, 2005:

I reread it and thought I wasn’t clear.
Basically, I interpreted the original regular expression to mean “the beginning of a string or anything but a back slash”  so I made it three backslashes so that it wouldn’t escape out the bracket when php read the string and when the regex engine got a hold of it.  But I can’t figure out if that is specifically what the programmer had in mind.

Eric

sunsetsystems wrote on Monday, May 16, 2005:

The regex strings that you referred to are single-quoted in the PHP code.  This means that PHP should not be escaping out the bracket.  In theory, ‘\]’ and ‘\\]’ should be identical (the backslash will escape either a single quote or another backslash but nothing else).  ‘\\\]’ will, I guess, be interpreted by PHP as ‘\\]’, as will ‘\\\\]’.

So again, I think this is some sort of PHP bug and unfortunately it will take some effort to solve your problem with reasonable confidence.

– Rod <rod at sunsetsystems dot com>