Jump to content

Need help with RegExp


Leo1906
 Share

Recommended Posts

Hello Guys,

I need a little help with an regular expression.
I have this String, for example this one: BNPA
and I want to check if the string only contains the letters A-G and M-Q. And I want every character to get checked, not only the first one. I came up with this one:

StringRegExp("BNPA", '([A-G][M-Q]){4}'))

But it returns 0. Without using the {4} it should generally be wrong, right? Because then it seems like it only checks the first character. Changing the second or third character to "Z" will still return true if I don't use the {4}.

Can anybody help me with that? :)

Thanks a lot :)

Link to comment
Share on other sites

20 minutes ago, mikell said:

You might use an alternation

$res = StringRegExp("BNPA", '([A-G]|[M-Q]){4}') 
Msgbox(0,"", $res)
$res = StringRegExp("BNZA", '([A-G]|[M-Q]){4}') 
Msgbox(0,"", $res)

 

Thanks a lot! That really does the job :)

But here's another one:

$res = StringRegExp("OX", '([A-C]|[L-Z]{2}')
Msgbox(0,"", $res)

I just tried to adapt what worked before ..
What am I missing this time? :/

So this time the String could be A-C AND/OR L-Z and always consist of two letters ..

Edited by Leo1906
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...