Regex exception

G

Geoff K

Hi
Should be easy but I can't work out the expression to raise an exception to
the string or sub string FAO
This doesn't work [a-zA-Z\-\.]\s?|(?!)FAO

A cell might acceptably contain
Name or
Name-Name or
Name - Name or
.. (dot)

but in error may contain
Name FAO or
Name-Name FAO or
Name - Name FAO or just
FAO

How can I prevent FAO from making a match?

Geoff
 
R

Rick Rothstein

Does it have to be a RegEx? What about a test something like this...

If Not TextValue Like "*[!a-zA-Z.-]*" And Right(TextValue, 3) <> "FAO" Then
MsgBox "Looks like a valid name to me"
Else
MsgBox "That name is not valid"
End If
 
G

Geoff K

Sorted....
Because I'm looking at first and last names I now look to match digits, / or
FAO with
"[/0-9]|F\s*A\s*O\s*" making sure that .IgnoreCase= True

It's worked so far.

Geoff
 
R

Ron Rosenfeld

Hi
Should be easy but I can't work out the expression to raise an exception to
the string or sub string FAO
This doesn't work [a-zA-Z\-\.]\s?|(?!)FAO

A cell might acceptably contain
Name or
Name-Name or
Name - Name or
. (dot)

but in error may contain
Name FAO or
Name-Name FAO or
Name - Name FAO or just
FAO

How can I prevent FAO from making a match?

Geoff

If you want to exclude any line that contains FAO, you could use the Replace
method with this regex:

".*FAO.*"

It will return a null string for any string that contains FAO.

Or you could use the Test method -- but the result would be False.
--ron
 
R

Ron Rosenfeld

If you want to exclude any line that contains FAO, you could use the Replace
method with this regex:

".*FAO.*"

It will return a null string for any string that contains FAO.

Or you could use the Test method -- but the result would be False.

Just to elaborate on the use of the Test method. If the string is to be
accepted (i.e. does NOT contain FAO), then the result of the Test method will
be false.
--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top