Jump to content
Sign in to follow this  
MyEarth

RegExp match with words

Recommended Posts

MyEarth

Hello

I need to use RegExp for check if a word match of a list of other words. Example $myvar = Apple, accepted word are Apple, Banana, Mango so match = 1. Accurate, example not accept Apples or Apple ABC, string must be equal but not case sensitive.

Thanks for any help

Share this post


Link to post
Share on other sites
mikell

(?i)  for case insensitivity
\bword\b   for word boundaries

No code provided => general response  :)

Share this post


Link to post
Share on other sites
MyEarth

No code provided? And what kind of code do you need? :D

I have try this way:

MsgBox(0,0,StringRegExp("Apple s", "(?i)\b(Apple|Banana|Mango)\b"))

Give me 1 so not work

Share this post


Link to post
Share on other sites
mikell

"Apples" does not match but "Apple s" does (word found)

$myvar = "Apple Bananas Mango"

$test = StringRegExp($myvar, '(?i)\b(apple|banana|mango)\b', 3)
If IsArray($test) Then Msgbox(0,"", UBound($test) & " matches")

 

Edited by mikell

Share this post


Link to post
Share on other sites
MyEarth

As i have say, the string must be equal but not case-sensitive, no other words in the string. If there are other words need to return 0 also if "partially" match like in the case of "apple s" or "apple abc"

Edited by MyEarth

Share this post


Link to post
Share on other sites
mikell

Ah OK, then you need anchors

$myvar = "Apple"

$test = StringRegExp($myvar, '(?i)^(apple|banana|mango)$')
Msgbox(0,"", $test)

 

Edited by mikell
  • Like 1

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.