LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
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.


 
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
Regular Expression Help on syntax Jason Excel Programming 25 January 10th 10 11:49 AM
Can someone help me with this regular expression? [email protected] Excel Discussion (Misc queries) 3 March 10th 09 07:36 PM
Regular Expression Conditionals (?(if)then|else) in VBA? Lazzaroni Excel Programming 7 October 8th 08 09:53 PM
Help with regular expression PO Excel Programming 3 May 2nd 07 01:39 PM
Regular Expression sl Excel Discussion (Misc queries) 2 January 23rd 07 11:57 PM


All times are GMT +1. The time now is 06:52 AM.

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"