Home All Groups Group Topic Archive Search About

Regular Expression Excluding Exact String

Author
22 May 2006 7:43 PM
Ross Ylitalo
I have been trying to put together a regular expression that will trap any
string with the exact string "&#" (without the quotes) and have been having
no luck.

Can anyone tell me if this is possible or not?  Even better, can anyone show
the regular expression I am looking for?

Thank you,

Ross Ylitalo
ross.ylitalo@gmail.comnospamplease

Author
22 May 2006 8:15 PM
Charlie Brown
This works, but I haven't tested it that much

[&][#]
Author
22 May 2006 9:20 PM
AlanT
If I understand you, you are looking to find any string that contains
"&#"

   e.g.
      "&#"
      "&#abc"
      "abc&#"
      "abc&#abc"

Where "abc" can be any characters.

Regex-wise you might try

     .*[&][#].*

but unless you have an overriding need to use regular expressions,  you
might try the string function IndexOf()

e.g.

      Dim str as string = "abc&#abc"
      MessageBox.Show(str.IndexOf("&#"))


If found, IndexOf() returns the 0-based index of the first char (i.e. 3
in the above example) or -1 if not found.


hth,
Alan.