Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   xsd regular expression query (http://www.velocityreviews.com/forums/t495148-xsd-regular-expression-query.html)

rorymo@gmail.com 03-30-2007 12:55 PM

xsd regular expression query
 
I have a regular expression that allows only certain characters to be
valid in an xml doc as follows:

<xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*" />

What I want to do is also allow any unicode character that is enclosed
in single quotes to also be valid, no matter where they appear. I
tried the following:

<xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*('*)*" />

But this only works if the characters in quotes appear after the other
text.

Any help would be much appreciated.

Regards
Rory


Bjoern Hoehrmann 03-30-2007 01:02 PM

Re: xsd regular expression query
 
* rorymo@gmail.com wrote in comp.text.xml:
>I have a regular expression that allows only certain characters to be
>valid in an xml doc as follows:
>
><xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*" />
>
>What I want to do is also allow any unicode character that is enclosed
>in single quotes to also be valid, no matter where they appear. I
>tried the following:
>
><xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*('*)*" />
>
>But this only works if the characters in quotes appear after the other
>text.


You are looking for "(a character from a certain set, or the character '
followed by zero or more characters except the character ' followed by
the character ') zero or more times", i.e. something like

([a-z]|'[^']*')*

if the first set of characters was a-z.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

rorymo@gmail.com 03-30-2007 01:30 PM

Re: xsd regular expression query
 
On Mar 30, 2:02 pm, Bjoern Hoehrmann <bjo...@hoehrmann.de> wrote:
> * ror...@gmail.com wrote in comp.text.xml:
>
> >I have a regular expression that allows only certain characters to be
> >valid in an xml doc as follows:

>
> ><xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*" />

>
> >What I want to do is also allow any unicode character that is enclosed
> >in single quotes to also be valid, no matter where they appear. I
> >tried the following:

>
> ><xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*('*)*" />

>
> >But this only works if the characters in quotes appear after the other
> >text.

>
> You are looking for "(a character from a certain set, or the character '
> followed by zero or more characters except the character ' followed by
> the character ') zero or more times", i.e. something like
>
> ([a-z]|'[^']*')*
>
> if the first set of characters was a-z.
> --
> Björn Höhrmann · mailto:bjo...@hoehrmann.de ·http://bjoern.hoehrmann.de
> Weinh. Str. 22 · Telefon: +49(0)621/4309674 ·http://www.bjoernsworld.de
> 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 ·http://www.websitedev.de/


Not quite - I want to allow the character(s) in quotes to be able to
appear with the character(s) from the specified set but not in any
particular place i.e. not necessarily at the beginning or end. For
example, I want the following to be valid:

dddd, d. MMMM yyyy
dddd, d. MMMM MyYear
MyDay, d. MMMM yyyy
dddd, d. MyMonth yyyy

so MyDay, MyYear and MyMonth appear in single quotes in the xml file
and are valid.



usenet@tech-know-ware.com 04-03-2007 11:46 AM

Re: xsd regular expression query
 
On 30 Mar, 14:30, ror...@gmail.com wrote:
> On Mar 30, 2:02 pm, Bjoern Hoehrmann <bjo...@hoehrmann.de> wrote:
>
>
>
>
>
> > * ror...@gmail.com wrote in comp.text.xml:

>
> > >I have a regular expression that allows only certain characters to be
> > >valid in an xml doc as follows:

>
> > ><xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*" />

>
> > >What I want to do is also allow any unicode character that is enclosed
> > >in single quotes to also be valid, no matter where they appear. I
> > >tried the following:

>
> > ><xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*('*)*" />

>
> > >But this only works if the characters in quotes appear after the other
> > >text.

>
> > You are looking for "(a character from a certain set, or the character '
> > followed by zero or more characters except the character ' followed by
> > the character ') zero or more times", i.e. something like

>
> > ([a-z]|'[^']*')*

>
> > if the first set of characters was a-z.
> > --
> > Björn Höhrmann · mailto:bjo...@hoehrmann.de ·http://bjoern.hoehrmann.de
> > Weinh. Str. 22 · Telefon: +49(0)621/4309674 ·http://www.bjoernsworld.de
> > 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 ·http://www.websitedev.de/

>
> Not quite - I want to allow the character(s) in quotes to be able to
> appear with the character(s) from the specified set but not in any
> particular place i.e. not necessarily at the beginning or end. For
> example, I want the following to be valid:
>
> dddd, d. MMMM yyyy
> dddd, d. MMMM MyYear
> MyDay, d. MMMM yyyy
> dddd, d. MyMonth yyyy
>
> so MyDay, MyYear and MyMonth appear in single quotes in the xml file
> and are valid.- Hide quoted text -
>
> - Show quoted text -


It looks to me that Björn's pattern achieves this. (Which filling in
the dots would be:

(^[ dgHhMmstyf,\-\./:;\\]|'[^']*')*

Can you do a test program and show some examples where it does not
work?

Cheers,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx/
http://www.codalogic.com/lmx/
=============================================


rorymo@gmail.com 04-04-2007 04:08 PM

Re: xsd regular expression query
 
On Apr 3, 12:46 pm, use...@tech-know-ware.com wrote:
> On 30 Mar, 14:30, ror...@gmail.com wrote:
>
>
>
>
>
> > On Mar 30, 2:02 pm, Bjoern Hoehrmann <bjo...@hoehrmann.de> wrote:

>
> > > * ror...@gmail.com wrote in comp.text.xml:

>
> > > >I have a regular expression that allows only certain characters to be
> > > >valid in an xml doc as follows:

>
> > > ><xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*" />

>
> > > >What I want to do is also allow any unicode character that is enclosed
> > > >in single quotes to also be valid, no matter where they appear. I
> > > >tried the following:

>
> > > ><xs:pattern value="^[ dgHhMmstyf,\-\./:;\\]*('*)*" />

>
> > > >But this only works if the characters in quotes appear after the other
> > > >text.

>
> > > You are looking for "(a character from a certain set, or the character '
> > > followed by zero or more characters except the character ' followed by
> > > the character ') zero or more times", i.e. something like

>
> > > ([a-z]|'[^']*')*

>
> > > if the first set of characters was a-z.
> > > --
> > > Björn Höhrmann · mailto:bjo...@hoehrmann.de ·http://bjoern.hoehrmann.de
> > > Weinh. Str. 22 · Telefon: +49(0)621/4309674 ·http://www.bjoernsworld.de
> > > 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 ·http://www.websitedev.de/

>
> > Not quite - I want to allow the character(s) in quotes to be able to
> > appear with the character(s) from the specified set but not in any
> > particular place i.e. not necessarily at the beginning or end. For
> > example, I want the following to be valid:

>
> > dddd, d. MMMM yyyy
> > dddd, d. MMMM MyYear
> > MyDay, d. MMMM yyyy
> > dddd, d. MyMonth yyyy

>
> > so MyDay, MyYear and MyMonth appear in single quotes in the xml file
> > and are valid.- Hide quoted text -

>
> > - Show quoted text -

>
> It looks to me that Björn's pattern achieves this. (Which filling in
> the dots would be:
>
> (^[ dgHhMmstyf,\-\./:;\\]|'[^']*')*
>
> Can you do a test program and show some examples where it does not
> work?
>
> Cheers,
>
> Pete.
> --
> =============================================
> Pete Cordell
> Tech-Know-Ware Ltd
> for XML to C++ data binding visit
> http://www.tech-know-ware.com/lmx/
> http://www.codalogic.com/lmx/
> =============================================- Hide quoted text -
>
> - Show quoted text -


The pipe(|) in you regular expression means 'or' right? If so then you
can only have the characters dgHhMmstyf,\-\./:;\\ OR characters in
quotes but not both in the same string so you can have:

dddd, d. MMMM yyyy
OR
'ab$olutN0n$en$e'
But not

dddd, d. MMMM yyyy 'ab$olutN0n$en$e'

Does this make sense?


usenet@tech-know-ware.com 04-04-2007 04:40 PM

Re: xsd regular expression query
 
On 4 Apr, 17:08, ror...@gmail.com wrote:
> On Apr 3, 12:46 pm, use...@tech-know-ware.com wrote:
>

....
> > It looks to me that Björn's pattern achieves this. (Which filling in
> > the dots would be:

>
> > (^[ dgHhMmstyf,\-\./:;\\]|'[^']*')*

>
> > Can you do a test program and show some examples where it does not
> > work?

>
> The pipe(|) in you regular expression means 'or' right? If so then you
> can only have the characters dgHhMmstyf,\-\./:;\\ OR characters in
> quotes but not both in the same string so you can have:
>
> dddd, d. MMMM yyyy
> OR
> 'ab$olutN0n$en$e'
> But not
>
> dddd, d. MMMM yyyy 'ab$olutN0n$en$e'
>
> Does this make sense?


But that's then wrapped in a set of brackets and a *. So you can have
any number of occurences of:

dddd, d. MMMM yyyy
OR
'ab$olutN0n$en$e'

which means you can have:

dddd, d. MMMM yyyy 'ab$olutN0n$en$e'

Note the pattern mentioned earlier is wrong. To match Bjorn's
suggestion it should not have had the first ^, so it becomes:

([ dgHhMmstyf,\-\./:;\\]|'[^']*')*

I recommend loading the pattern into whatever is the most convenient
regular expression parser for you such as Perl, PHP, Java, C#,
Javascript, and developing a number of test cases. Then check that
each one passes or fails as is appropriate. Then where there's
errors, list them here.

If you don't have a convenient regular expression engine locally you
might be able to download a pure regular expression tester, or do
something on the web such as: http://www.nvcc.edu/home/drodgers/ce...est_regexp.asp

BTW - when testing a regular expression destined for a schema on a
normal regular expression engine, remember to put ^ and $ anchors
around it.

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx/
http://www.codalogic.com/lmx/
=============================================


rorymo@gmail.com 04-05-2007 03:49 PM

Re: xsd regular expression query
 
On Apr 4, 5:40 pm, use...@tech-know-ware.com wrote:
> On 4 Apr, 17:08, ror...@gmail.com wrote:
>
>
>
>
>
> > On Apr 3, 12:46 pm, use...@tech-know-ware.com wrote:

>
> ...
> > > It looks to me that Björn's pattern achieves this. (Which filling in
> > > the dots would be:

>
> > > (^[ dgHhMmstyf,\-\./:;\\]|'[^']*')*

>
> > > Can you do a test program and show some examples where it does not
> > > work?

>
> > The pipe(|) in you regular expression means 'or' right? If so then you
> > can only have the characters dgHhMmstyf,\-\./:;\\ OR characters in
> > quotes but not both in the same string so you can have:

>
> > dddd, d. MMMM yyyy
> > OR
> > 'ab$olutN0n$en$e'
> > But not

>
> > dddd, d. MMMM yyyy 'ab$olutN0n$en$e'

>
> > Does this make sense?

>
> But that's then wrapped in a set of brackets and a *. So you can have
> any number of occurences of:
>
> dddd, d. MMMM yyyy
> OR
> 'ab$olutN0n$en$e'
>
> which means you can have:
>
> dddd, d. MMMM yyyy 'ab$olutN0n$en$e'
>
> Note the pattern mentioned earlier is wrong. To match Bjorn's
> suggestion it should not have had the first ^, so it becomes:
>
> ([ dgHhMmstyf,\-\./:;\\]|'[^']*')*
>
> I recommend loading the pattern into whatever is the most convenient
> regular expression parser for you such as Perl, PHP, Java, C#,
> Javascript, and developing a number of test cases. Then check that
> each one passes or fails as is appropriate. Then where there's
> errors, list them here.
>
> If you don't have a convenient regular expression engine locally you
> might be able to download a pure regular expression tester, or do
> something on the web such as:http://www.nvcc.edu/home/drodgers/ce...est_regexp.asp
>
> BTW - when testing a regular expression destined for a schema on a
> normal regular expression engine, remember to put ^ and $ anchors
> around it.
>
> HTH,
>
> Pete.
> --
> =============================================
> Pete Cordell
> Tech-Know-Ware Ltd
> for XML to C++ data binding visithttp://www.tech-know-ware.com/lmx/http://www.codalogic.com/lmx/
> =============================================- Hide quoted text -
>
> - Show quoted text -


I have it working now. Thanks a lot to all who replied.

-Rory.



All times are GMT. The time now is 03:46 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.