xsl-list
[Top] [All Lists]

Re: [xsl] XPath 2.0 Regex misunderstanding

2007-01-19 15:43:20
cknell(_at_)onebox(_dot_)com wrote:
Thanks. I eventually figured out what I needed. I made the match alternatives more explicit and refreshed my memory on the grouping and alternation symbols, and I got something that worked for me.
After looking at your solution, I shortened it to this:
not(matches(DATE,'^(0[1-9]|1[0-2])/([0-2]\d|3[01])/(2005|2006|2007)'))

That has over 70% fewer characters than my original expression, a welcome 
result.

If fewer characters is what you are after, than you can make it still a bit shorter by doing this

^(0[1-9]|1[0-2])/([0-2]\d|3[01])/(200[5-7])


You seem to be missing the $ anchor matching the end of the string. Do you not want to match the whole string? Note that your match matches:
01/01/2006something

Also, I happen to have a regex that takes months being 28, 30 or 31 days into account, however I stopped trying to find out the leap years regexes as these are a bit harder (and calculation is easier).

Doesn't this already sound awefully obfuscated?



I used to write a lot of text document parsing programs in Perl, and I was very 
sharp with regular expressions. I have gotten a bit rusty since then.

Good ol' Jeffrey Friedl called it an art. And isn't an art supposed to be given regular practice? ;)


My requirement is that the date part of the field I am parsing be in this format "MM/DD/YYYY", with 
no skipped characters (that is to say, "01/05/2006" is perfect, while "1/5/06" should 
fail on three counts. I re-route the records with bad formats back to the data entry people to correct.

Whenever I think of writing regexes, my mind immediately goes to the "Obfuscated 
Perl Contest" that the Perl Journal used to sponsor.

Same here, I did it from 1998. I have a dear friend that is still a hardcore Perl programmer. I have loved the language (still do) for its brevity and speed. And of course, it gave regular expressions a whole new face (or dare I say era?)

Cheers,
-- Abel Braaksma
  http://www.nuntia.nl


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>