Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 24th, 2006, 10:58 AM   #1
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
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?
mackenga is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:50 PM.

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