Sign in to follow this  
Followers 0
MyEarth

RegExp match with words

7 posts in this topic

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



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

No code provided => general response  :)

Share this post


Link to post
Share on other sites

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

#4 ·  Posted (edited)

"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

#5 ·  Posted (edited)

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

#6 ·  Posted (edited)

Ah OK, then you need anchors

$myvar = "Apple"

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

 

Edited by mikell
1 person likes this

Share this post


Link to post
Share on other sites

Last seems work as i need. Thanks

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  
Followers 0