|Think about Loose Coupling|
Re: regex logical equivalence?by jarich (Curate)
|on Feb 05, 2004 at 06:14 UTC||Need Help??|
I think you might find it worthwhile to learn about /x at this point as these regular expressions could certainly do with some commenting. /x isn't hard or scary at all. All you have to do is rememeber to escape the whitespace you want and the #s. It makes regular expressions much easier to explain.
Just to make things more confusing ;) I'm going to swap the order of these two expressions, so my first one will be the longer of the two and I'll work on the the shorter (my second - your first) as I think that's the one you wanted to focus on.
To determine if your two regular expressions are suffiently equivalent we need to compare them.
This is the longer one:Now we need to consider what patterns will match one, but not the other... (I'm going to assume you are missing a * up there next to your ], if not, then these aren't very equivalent at all).
and this the shorter:
Like you, I can only spot this one significant difference between the two regular expressions (once you fix your typo).
This is easily fixed:Note that this equivalence won't necessarily remain true if you change your quantifiers. In particular if you change all of your *s to ?s. If you want my opinion I suspect you're actually looking more for a regular expression like this:
But I may be wrong - you may not be interested in the dot at all. ;) I'm not 100% certain that you want the .* at the front though. Do you have some sample data for us?
I hope you recognise that both expressions will match any string with a single space in it... which will be most strings....
I hope this helps.