Forum Moderators: coopster

Message Too Old, No Replies

PHP Regex help

         

darkmasta

4:56 am on Jan 26, 2005 (gmt 0)

10+ Year Member



I want a regex that would work as follows: I have a string like {hey.yo.wat}, the string is by itelf and always must start with a { and end with a }, the first backreference would contain a 'hey.yo.', the second 'yo.' and the third, 'wat'. If the string is only something like {hey.yo}, you would get 'hey.' for the first and second backreferences and 'yo' would be the third backrefernce. How should I build the regex?

darkmasta

11:44 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



the strings between the dots must be alphanumeric. Thus {\.&*.%$} would pass on your regex. That is not good.

ergophobe

4:43 am on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No it wouldn't. Those tests are with the same character range as you are using. See message 17.

darkmasta

9:09 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



{(([^\.]+\.)+)([^\.]+)\} matches {$%^.%&.(\}

ergophobe

9:29 pm on Feb 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For the third or fourth time I know that! See message 17.

That is NOT the regex I'm using. I'm testing with the same character range that you are [a-z0-9-_]

For short strings it is faster than yours, for long strings (over about 25 chars with eight or so atoms) it is slower.

darkmasta

10:24 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



Heh, sorry. Anyway, I think a more elegant solution can be made without loopin a regex.
This 35 message thread spans 2 pages: 35