Re: strings vs regular expressions



Hi AVL,

Just to clear things up regarding regular expressions versus string
functions. Use regular expressions when looking for a *pattern* of
characters in a string, which may be different characters in the same
pattern, and string functions for looking for substrings. What I mean by
"patterns" is, for example, a hyperlink in an HTML document.

A hyperlink is a string that must follow certain rules. It must begin with
the character sequence "<a" followed by one or more white space characters,
followed by 0 or more attribute name=value pairs, followed by the ">"
character. This is followed by a string of text that is followed by the
"</a>" character sequence. Note that only several of the characters are
specified, and you don't know what the rest of them will be. So, how do you
look for a string that satisfies these rules? Example:

(?m)(?i)(?<=<a)(?:(?:\s+href=(?<href>[^>]+))|(?:\s+[^=>]+=[^>]+))*>(?<innerHtml>[^<]*)(?=</a>)

The above is a regular expression that identifies substrings that satisfy
those rules. In addition, it captures 2 groups, one for the link text, one
for the innerHtml of the anchor.

You could not use a string function to find this pattern. Generally, string
functions are faster than regular expressions, but when looking for patterns
(groups of characters that satisfy rules), regular expressions are the
fastest method.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"AVL" <AVL@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A15C2E96-968B-4323-A3BF-D1F5663FB776@xxxxxxxxxxxxxxxx
hi,
I need to comapare or check for substrings in a given string.
which would give better performance - string related comapare functions or
regualr expressions....


.



Relevant Pages

  • Re: Extract letters and numbers from string
    ... While the Like operator patterns cannot begin to compare to those from a Regular Expression parser, they are still quite flexible and you can still get quite complex with them. ... What the pattern does is insure the text in the variable Value is made up of nothing but digits. ... The exclamation mark inside the square brackets says to look for characters NOT in the range 0 through 9, the asterisks on either side says to look for this non-digit anywhere within the text contained in the Value variable. ... > Public Function AlphaNumeralsAs String ...
    (microsoft.public.excel.programming)
  • Re: Extract letters and numbers from string
    ... While the Like operator patterns cannot begin to compare to those from a ... exclamation mark inside the square brackets says to look for characters NOT ... the Like pattern tests can all be included into a single pattern test... ... Public Function AlphaNumeralsAs String ...
    (microsoft.public.excel.programming)
  • Re: RegEx: How to ignore the number of whitespaces?
    ... matching character sequences in strings. ... what are the limitations of the "arbitrary Unicode characters?" ... Exactly one of them must be found in the string, ... Certain subsequences of a pattern may be marked as optional. ...
    (microsoft.public.dotnet.framework)
  • Re: what is the quickest way to find out whether a string contains another string?
    ... Why would anyone want to use regular expressions to look for a plain ... Regular expressions are a tool for deciding whether a String or ... searching is a trivial degeneration of the problem addressed by regular ... input string into a pattern that matches only itself is the first task. ...
    (comp.lang.java.programmer)
  • Re: ACT scripting
    ... While executing the the script send by you..I am getting the following ... > 1) Assuming the pattern you are looking for is unique in the file, ... > 'string to search ... > Regular Expressions. ...
    (microsoft.public.scripting.vbscript)