Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 28th, 2012, 12:45 PM
Marionette Marionette is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Marionette User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 50 sec
Reputation Power: 0
Need a Regex Guru

i'm working with an xsd that cannot change that has a regex restriction value that determines the validation format. i am taking this xsd and automagically generating a wrapper class which then is generically parsed via reflection.

what i'd like to know, is it possible to parse an example of the following regex strings (these could be anything since i won't know what string i'll encounter):

[0-9]{4}-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))T(([01][0-9])|(2[0-3])):[0-5][0-9](:[0-5][0-9])?(Z|([\+\-](([01][0-9])|(2[0-3]))(:[0-5][0-9])?))?

-OR-

(([01][0-9])|(2[0-3])):[0-5][0-9](:[0-5][0-9])?(Z|([\+\-](([01][0-9])|(2[0-3]))(:[0-5][0-9])?))?

-OR-

$|([A-Z][A-Z]?)

to obtain it's constiuent parts to create a format string thusly: "yyyy-mm-ddThh:mm:ss" ?

or better yet, dynamically create a new replacement regex based on the validation regex?

i know i'm probably talking about a lexer/parser/tokenizer etc, but just looking at this it *should* be possible, right?

please note, the point is to determine the format strictly from the regex validation string and it cannot change. i'd liek to dynamically parse it to create a replace regex string or generate a format string to use with a DateTime object etc..

i appreciate your help in advance..

Reply With Quote
  #2  
Old December 28th, 2012, 05:45 PM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 502 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 18 h 50 m 40 sec
Reputation Power: 385
I understand what you are talking about, but not really what you want.

Code:
[0-9]{4}-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))


is clearly a right way to match yyyy-mm-dd and check that the date is within some valid constraints, but do you need to be so strict?

Wouldn't something like this:

Code:
\d{4}(-\d\d){2}


be sufficient to match a validly formatted expression looking as a date?

(I did not say a valid date, but your quite complicated expression will also fail to see that 2012-02-29 or even 2012-02-31 is not a valid date. So, the bottom line, is: do you want to validate a date format, in which case my much simpler expression might be sufficient, or do you want to validate a date, in which case a regular expression is probably not what you are looking for).

Reply With Quote
  #3  
Old December 28th, 2012, 05:57 PM
Marionette Marionette is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Marionette User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by Laurent_R
I understand what you are talking about, but not really what you want.

Code:
[0-9]{4}-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))


is clearly a right way to match yyyy-mm-dd and check that the date is within some valid constraints, but do you need to be so strict?

Wouldn't something like this:

Code:
\d{4}(-\d\d){2}


be sufficient to match a validly formatted expression looking as a date?

(I did not say a valid date, but your quite complicated expression will also fail to see that 2012-02-29 or even 2012-02-31 is not a valid date. So, the bottom line, is: do you want to validate a date format, in which case my much simpler expression might be sufficient, or do you want to validate a date, in which case a regular expression is probably not what you are looking for).


so to be a bit more in-depth, the regex string above isn't mine, it's part of an overall xsd (xsd:restriction/xsdattern) that needs to be untouched, bugs and all unfortunately ;(

which is another reason why i would like to be able to dynamically generate a new replace string based off of their validation string. since my code walks the object via reflection, i cannot obtain enough information dynamically to discern what the format is supposed to be. thus my choices are to somehow be able to figure out what format is inferred by the validation regex, or to hard code the format into my dynamic code..

we will be using this automation scheme to download the xsd -> autogen the wrapper classes from it -> generate a gui with the appropriate controls per type -> serializing the object after manipulation -> calling a webservice with the resultant xml. using it this way means that if they ever make changes all we ever have to do is obtain the xsd, and then everything else is autogen'd from it, thus no recoding etc..

unfortunately, i have no control over the regexes contained in the pattern elements, they are what they are ;(

Reply With Quote
  #4  
Old December 29th, 2012, 03:27 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 502 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 18 h 50 m 40 sec
Reputation Power: 385
Just taking again only the first part of your regex to simplify the discussion:

Code:
[0-9]{4}-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))


will match, for example, "2012-12-29", but will not capture the year. "((0[1-9])|(1[012]))" will capture "12" and "((0[1-9])|([12][0-9])|(3[01]))" will capture "29". From there on, you can try to figure out what substitution will be possible.

Reply With Quote
  #5  
Old January 2nd, 2013, 12:27 PM
Marionette Marionette is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Marionette User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by Laurent_R
Just taking again only the first part of your regex to simplify the discussion:

Code:
[0-9]{4}-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))


will match, for example, "2012-12-29", but will not capture the year. "((0[1-9])|(1[012]))" will capture "12" and "((0[1-9])|([12][0-9])|(3[01]))" will capture "29". From there on, you can try to figure out what substitution will be possible.


i am by no stretch of the imagination completely up on regex, let alone being a guru..

would you happen to have something to start me off? or a link that might deal with something like this?

Reply With Quote
  #6  
Old January 3rd, 2013, 06:57 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 502 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 18 h 50 m 40 sec
Reputation Power: 385
These are useful tutorials on regular expression in Perl:

Quick introduction:
http://perldoc.perl.org/perlrequick.html

More detailed tutorial:
http://perldoc.perl.org/perlretut.html

Very detailed reference:
http://perldoc.perl.org/perlre.html

I think it will explain many things to you, even if you are using another programming language than Perl (most modern regex packages are directly derived from the Perl regexes), but you can also look into the tutorials for your own language (it is not Perl).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Need a Regex Guru

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap