You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Hollenbeck, Scott" <sh...@verisign.com> on 2001/04/06 14:12:58 UTC
Alternative Order in Regular Expressions
I'm using Xerces-J 1.3.1, and I noticed an interesting anomaly when working
with regular expressions in a pattern facet yesterday. I was trying to
create a pattern that would match either an empty element or a string
element in a specific format, like this:
<contact:fax>+1.7034444444</contact:fax> or <contact:fax/>
This pattern seems to work:
<pattern value="(\+[0-9]{1,3}\.[0-9]{1,12})|.{0,0}"/>
This one (switching the order of the choices) doesn't:
<pattern value=".{0,0}|(\+[0-9]{1,3}\.[0-9]{1,12})"/>
>java sax.SAXCount -v foo.xml
[Error] foo.xml:23:52: Datatype error: In element 'contact:fax' : Value
'+1.7034444444' does not match regular expression facet
'.{0,0}|(\+[0-9]{1,3}\.[0-9]{1,12})'..
foo.xml: 1231 ms (22 elems, 5 attrs, 273 spaces, 108 chars)
>
Why is the order of these choices significant?
<Scott/>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Alternative Order in Regular Expressions
Posted by René Jensen <lu...@tbkol.dk>.
Citat "Hollenbeck, Scott" <sh...@verisign.com>:
---8>< [CUT] 8><---
> <contact:fax>+1.7034444444</contact:fax> or <contact:fax/>
>
> This pattern seems to work:
> <pattern value="(\+[0-9]{1,3}\.[0-9]{1,12})|.{0,0}"/>
>
> This one (switching the order of the choices) doesn't:
> <pattern value=".{0,0}|(\+[0-9]{1,3}\.[0-9]{1,12})"/>
---8>< [CUT] 8><---
Well unfortunately I don't have the answer to your question,
but i have a solution, that I personally prefer.
I would have made the RegEx like this.
(\+[0-9]{1,3}\.[0-9]{1,12})?
substituting "|.{0,0}" with "?"
_\|/_
(@ @)
---oOOo-(_)-oOOo---
René Jensen
lundeman@tbkol.dk
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org