View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld[_2_] Ron Rosenfeld[_2_] is offline
external usenet poster
 
Posts: 1,045
Default Basic regular expression question

On Sat, 16 Apr 2011 22:37:36 -0700, "Robert Crandal" wrote:

I plan to basically reuse the code you gave me previously, but I need to
modify
the regular expression pattern so that the variable mc(0).submatches(1)
would get assigned strings like "scissors", or "red notebooks", or
"number #2 pencils"

How should I change the pattern string?

Thankx!


If the "object" will be all on the same line:

"^(\w+)\s+(.+)"

However, because of the peculiarities of MS implementation in vba, if the "object" might span a second line, then you should use:

"^(\w+)\s+([\s\S]+)"

As an aid to writing and testing regular expressions, I would suggest a program titled RegexBuddy (www.regexbuddy.com)

And, as Rick is so fond of pointing out, you can do most anything using built-in VBA methods without using Regular Expressions, and they will often run more quickly if that is an issue. However, once you become fluent in Regular Expressions, it takes much less time to develop complex string manipulations using them than using VBA.

Of course, if speed is paramount, I suppose we should be writing in machine language <g.