RegEx HELP!!!

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

RegEx Help

Need RegEx for extracting the XY*13*17*22*90 from the given document.
............
AB*1*1*12*9
XY*13*17*22*90
BS*1*1*4*9
............

TIA
 
Hmmm... this sounds like a homework problem.....

If the is the *only* requirement (specifically, that is the *only* document
this will be used on), then
^X.*$
should be sufficent. (That's an "X", at the start of a line "^", followed
any character "." repeated any number of times "*" until the end of the
line "$")

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
 
Thanks James, It isn't a homework problem, I want to seek RegEx solution...I
know how to solve this by reading line by line and landing on the record.
I sincerely appreciate your help

XY*13*17*22*90 //This line has 22 and XY as a fixed value rest all are
variables so I am trying to come with a pattern
^XY*[0-9][0-9]...something like it...The only problem is * is making my LIFE
HELL I tried escaping but that isn't workn
XY*14*1*22*100
XY*15*37*22*52


TIA


James Curran said:
Hmmm... this sounds like a homework problem.....

If the is the *only* requirement (specifically, that is the *only* document
this will be used on), then
^X.*$
should be sufficent. (That's an "X", at the start of a line "^", followed
any character "." repeated any number of times "*" until the end of the
line "$")

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

Vai2000 said:
RegEx Help

Need RegEx for extracting the XY*13*17*22*90 from the given document.
...........
AB*1*1*12*9
XY*13*17*22*90
BS*1*1*4*9
...........

TIA
 
In the simpliest form : ^XY.*\*22\*.*$

^ (anchor to start of string)XY
.. (any character)
* (zero or more times)
*22*
.. (any character)
* (zero or more times)
$ (anchor to end of string)

Now since we probably don't want a false positive on XY*22*17*13*90, we
really want :
^XY\*\d\d\*\d\d\*22\*\d\d$

^ (anchor to start of string)XY*
Any digit
Any digit
*
Any digit
Any digit
*22*
Any digit
Any digit
$ (anchor to end of string)



A suggestion: Go to
http://blogs.msdn.com/ericgu/archive/2003/07/07/52362.aspx and download Eric
Gunnerson's Regular Expression Workbench. It make building & interpreting
regexes easy (... um...easier). (I copy'n'pasted the interpretations it
produced above)

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

Vai2000 said:
Thanks James, It isn't a homework problem, I want to seek RegEx solution...I
know how to solve this by reading line by line and landing on the record.
I sincerely appreciate your help

XY*13*17*22*90 //This line has 22 and XY as a fixed value rest all are
variables so I am trying to come with a pattern
^XY*[0-9][0-9]...something like it...The only problem is * is making my LIFE
HELL I tried escaping but that isn't workn
XY*14*1*22*100
XY*15*37*22*52


TIA


James Curran said:
Hmmm... this sounds like a homework problem.....

If the is the *only* requirement (specifically, that is the *only* document
this will be used on), then
^X.*$
should be sufficent. (That's an "X", at the start of a line "^", followed
any character "." repeated any number of times "*" until the end of the
line "$")

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

Vai2000 said:
RegEx Help

Need RegEx for extracting the XY*13*17*22*90 from the given document.
...........
AB*1*1*12*9
XY*13*17*22*90
BS*1*1*4*9
...........

TIA
 
Assuming the pattern starts with an XY and then is followed by one or more
*digit(s) sequence, the following RegEx can be used to extract the specified
pattern

XY(\*\d+)+

Vihar
 
Back
Top