Regular Expression

  • Thread starter Thread starter asadikhan
  • Start date Start date
A

asadikhan

Hi,

I want to create a regular expression. I have come up with something
like this:

Scan*ValRel(QualValRel)*

which basically means that I should see:

zero or more of "Scan"
exactly one of "Val"
exactly one of "Rel"
zero or more of "ScanValRel"

however I can't seem to get this right. I used Expresso as well to try
to come up with the right expression. The closest I got was:

(Scan)*(Val)(Rel)(QualValRel)*

but this allows

ScanValValRel (as it finds ValRel as part of this string). I don't want
it to do that.

As specified above, I want to find exactly one of Val (no more) etc.

How do I do this?
 
I'm not sure I have understood what you want.
This RegEx may be what you are looking for :
^(Scan)*(Val){1}(Rel){1}(QualValRel)*$
It meens that you want a string starting with zero or more of "Scan",
followed by exactly one "Val", followed by exactly one "Rel" and possibly
followed by zero or more of "QualValRel".

For an example, ScanScanScanScanValRelQualValRelQualValRel will give 4
"Scan", 1 "Val", 1 "Rel" and 2 "QualValRel".
ScanScanValValRelQualValRel will not match because there are 2 "Val".

Hope it helps.

Ludovic SOEUR.
 
Hi,

I want to create a regular expression. I have come up with something
like this:

Scan*ValRel(QualValRel)*

which basically means that I should see:

zero or more of "Scan"
exactly one of "Val"
exactly one of "Rel"
zero or more of "ScanValRel"

however I can't seem to get this right. I used Expresso as well to try
to come up with the right expression. The closest I got was:

(Scan)*(Val)(Rel)(QualValRel)*

but this allows

ScanValValRel (as it finds ValRel as part of this string). I don't want
it to do that.

As specified above, I want to find exactly one of Val (no more) etc.

How do I do this?

Simply put ^ and $ at the start and end (respectively) of your pattern,
to require that the *whole* of the input string matches the *whole* of
the pattern
 
Back
Top