Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Perl (http://www.programmingforums.org/forum21.html)
-   -   Fifth coffee, not focusing well on this RegExp (http://www.programmingforums.org/showthread.php?t=8091)

mackenga Jan 24th, 2006 10:58 AM

Fifth coffee, not focusing well on this RegExp
 
This actually seems to be working, but I'm having trouble reasoning about it. I'm actually working in Tcl at the moment but since it's a RegExp question I decided this would be the best place for it. Basically, I'd appreciate anyone's input as to whether this does what I think it does, and whether it does it well.

At one point I have a string containing zero or more name=value pairs, much like the parameters to an HTML tag. Like those, the values may or may not be quoted; they're either single-quoted or double-quoted strings, or sequences of nonwhitespace characters. Strings may include difficult characters (like a double quote in a double-quoted string, or a single quote in a single quoted string, amongst other things) by preceding them with a backslash. I'm using the Tcl regexp command with the -all and -inline options to get a list of all matches and submatches in a predictable order.

:

\s*([^\s=]+)\s*=\s*(?:([^"'\s]+)|"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)')

I've been staring at it too long to feel certain that it's as good as it's going to get. Any ideas?


All times are GMT -5. The time now is 1:07 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC