[xquery-talk] regular expression question
Tony Stubblebine
tonys at oreilly.com
Tue Jun 28 15:23:11 PDT 2005
Hi Howard,
I think you'd want something like this: "^[^;]*,[^;]*$"
That reads as, start at the beginning of the string match any number of
non-semi-colon characters, followed by a comma, followed by any number
of non-semi-colon characters, followed by the end of string.
The result is that you'll have at least one comma and zero semi-colons.
Here's some test code that I whipped up for CQ
for $p in ("foo", "bar,foo", ";foo,bar,gold", "foo,bar,go;ld",
"foo;bar;gold,")
return
if (matches($p, "^[^;]*,[^;]*$"))
then <p>Matches: {$p} </p>
else <p>No Match: {$p} </p>
--Tony
Howard Katz wrote:
> I haven't done much to date with regular expressions, so here's what I'm
> sure is a very easy question (if you know the answer! :-)
>
> I have <p> elements containing text that is separated internally by either
> comma or semicolon delimiters or both. I want a regular expression that'll
> let me tokenize a <p> element into its constituent pieces only if it
> contains one or more comma separators and *doesn't* contain a semicolon. Ie,
> what's goes in the regular expression slot for
>
> for $p in ... /p
> return
> if ( fn:matches( $p, " ??? comma-yes semicolon-no ??? " ))
> then let $tok := fn:tokenize( $p, "," )
> else ...
>
> TIA,
> Howard
>
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
More information about the talk
mailing list