On 8/23/05, Richard Lynch <ceo@xxxxxxxxx> wrote: > The advantage that when I have to change the string to match the > new/altered data, and that data has, oh, I dunno, something like ' or > \ or 0, 1, 2, 3, ...9 in it, and then my Regex suddenly doesn't work > because \abc7 won't work the same as \7abc but \\abc7 works the same > as \\7abc Ummm... no it doesn't. Both of these will fail to compile: preg_match( '/\\7abc/', $myString); preg_match( '/\7abc/', $myString); Both of these are fine: preg_match( '/\\abc7/', $myString); preg_match( '/\abc7/', $myString); In fact they behave *exactly* as if you hadn't doubled them up. You've not achieved anything, but you've made your regexp just a little more difficult to read and maintain. > I guess I just like things that ALWAYS work instead of things that > SOMETIMES work. Silly me. > > \\ always works > \ only works sometimes, depending on what character follows it. No it doesn't. Indiscriminately doubling up all your back-slashes is not an alternative to actually learning the proper syntax. > PS > A Regex is unreadable code by definition anyway. > > \\ isn't any more unreadable, with practice, than \, especially if you > are CONSISTENT and use it in PHP all the time, not just in Regex. Yeah, "with practice" you can get used to anything... Unfortunately I'm not the only developer here. There are three teams of programmers who would take umbrage with any need to practice before reading my code. > > But the sheer number of weird character combinations and positional > difference (^ inside [] and ^ outside [] and ^ at the beginning of > either are all COMPLETELY different) make Regex unreadable no matter > how long you stare at it. With practice... No, you're absolutely right. The way operators change meaning depending on context can be confusing, especially when you're getting started. They're addressing this already with the design of Perl 6. No doubt it'll trickle through to PHP in due course. http://dev.perl.org/perl6/doc/design/apo/A05.html#Too_compact_and_"cute" But in the mean time, it's not *that* hard to learn the syntax of regular expressions. OK, they're rather terse. But apart from that, they're a lot simpler than a proper language like PHP and you don't seem to have problems with that. > I dunno what masochist invented this Regex crap, but he oughta be shot Computational Linguists, first up against the wall, come the revolution. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php