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

On Sat, 2 Feb 2013 00:29:55 -0700, "Robert Crandal" wrote:

"Ron Rosenfeld" wrote in message
.. .

That being the case, a regex such as:

^(\S+)(?:\s+(.+))?

should be all that you need.


Hi Ron. Just out of curiousity, what is the meaning of the colon
in the above pattern string?


You should have access to a comprehensive definition of the syntax for the relevant flavor if you are going to be using regular expressions.
Here is a link to the syntax used in the VBscript flavor: http://msdn.microsoft.com/en-us/libr...=vs.84%29.aspx

From that link:

==========================
(?:pattern)

Matches pattern but does not save the match, that is, the match is not stored for possible later use. This is useful for combining parts of a pattern with the "or" character (|).

industr(?:y|ies) is equivalent to industry|industries.
===========================

So using this makes the regex more efficient, as it does not have to store the part of the match that includes the spaces between the two elements that we want to match.