Regular Expression

  • Thread starter Thread starter Marcel Hug
  • Start date Start date
M

Marcel Hug

Hi !
I have a question to a regular expression.
I have the following strings:

NA-NC-ND-QF-ZC
and
NA-NC-ND-QF-QG-ZB

Now I'm looking for a regular expression which helps mi to get all codes
(the order of the NB-NC-QF... could be changed) which do not have a QG code.
How can I do that ?

Thanks
Regards
Marcel Hug
 
If QG is never at the beggining or the end of the string, use this regex :
^.*$(?<!.*-QG-.*)
Otherwise :^(?!QG-).*$(?<!.*-QG-.*)(?<!.*-QG)

Hope it helps,

Ludovic SOEUR.
 
Salu Ludovic !
Thanks for your help. The regex did not properly work.
In my case at the begin i have a fix product text like. PRD522-R01
Then I checked, if the QF is existing and after that i would like to check,
if the QG does not exist.

I tried this one:

PRD522-R01.*QF1(?!(-QG)).*$(?<!QG[0-9])

I'm not sure if this is really the right syntax of regex.
Could you do a little review ? thanks

regards
marcel
 
Salut Marcel,

OK, you did not say exactly how are your product codes. If I had understood,
this following regex should work :
^PRD522-R01.*-QF(?!.*-QG).*$
Explanations :
^PRD522-R01 means you want a code STARTING with PRD522-R01
..*-QF containing at least -QF
(?!.*-QG) but not followed by -QG
..*$ until the end of the code


But if QG can appear before QF, use this one instead:
^PRD522-R01.*-QF.*$(?<!-QG.*)
Explanations :
^PRD522-R01 means you want a code STARTING with PRD522-R01
..*-QF.*$ and then containing -QF
(?<!-QG.*) and must not contain -QG



Hope this helps,

Ludovic Soeur.


Marcel Hug said:
Salu Ludovic !
Thanks for your help. The regex did not properly work.
In my case at the begin i have a fix product text like. PRD522-R01
Then I checked, if the QF is existing and after that i would like to check,
if the QG does not exist.

I tried this one:

PRD522-R01.*QF1(?!(-QG)).*$(?<!QG[0-9])

I'm not sure if this is really the right syntax of regex.
Could you do a little review ? thanks

regards
marcel



Ludovic SOEUR said:
If QG is never at the beggining or the end of the string, use this regex :
^.*$(?<!.*-QG-.*)
Otherwise :^(?!QG-).*$(?<!.*-QG-.*)(?<!.*-QG)

Hope it helps,

Ludovic SOEUR.


"Marcel Hug" <[email protected]> a écrit dans le message de
 
Back
Top