Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Regex exception

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Regex exception

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

--
Rick (MVP - Excel)


"Geoff K" wrote in message
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Regex exception

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

"Geoff K" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Regex exception

On Thu, 15 Oct 2009 08:56:46 -0700, Geoff K
wrote:

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Regex exception

On Fri, 16 Oct 2009 20:26:04 -0400, Ron Rosenfeld
wrote:

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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex Pattern Geoff K Excel Programming 5 June 12th 09 12:49 AM
Exception from HRESULT: 0x800A03EC - COM Exception Unhandled Karthizen[_2_] Excel Programming 3 March 16th 09 09:54 PM
Help with a regex pattern please [email protected] Excel Programming 3 March 22nd 08 12:14 AM
Regex techniques Dave Runyan Excel Programming 5 April 28th 07 12:17 AM
RegEx to parse something like this... R Avery Excel Programming 2 March 7th 05 06:41 PM


All times are GMT +1. The time now is 09:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"