Jump to content

RegEx help


ale1981
 Share

Go to solution Solved by jguinch,

Recommended Posts

Can somebody help me with this RegEx expression?

I have tried but can't seem to get it to work, what I need is to verify a string, the string can only contain these characters ( C, X, J, P, L, B ) and numbers but must also be in this format;

[char][number][space][char][number]......

e.g.

C1 X4 B1

C3

 

Is this something RegEx can do?

 

Thanks in advance.

Edited by ale1981
Link to comment
Share on other sites

$string = "C1 X4 B1"
; $string = "C1 X4 B1 X9 J0"
If StringRegExp($string, "^([BCJLPX]\d)( [BCJLPX]\d)*$") Then ConsoleWrite("ok")

Match

C1 X4 B1

C1 X4 B1 X9 J0

Edited by jguinch
Link to comment
Share on other sites

  • Solution

@kylomas : your expression matches something like C1 C1 C1 C1 only (where 1 is the group value, not the expression). Use (?1) instead if 1 :

If StringRegExp($string, "^([BCJLPX]\d)( (?1))*$") Then ConsoleWrite("ok")
Edited by jguinch
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...