Re: regular expressions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> schrieb:
need to verify a string against reg exp. to allow only characters and apostrophe and hyphen

using :
========
Function RegExpValidate(sInput,sPattern) as boolean
Dim RegexObj as Regex = New Regex("regularexpression")
return Regex.IsMatch(sInput,sPattern)
End Function

calling with:
==============
RegExpValidate(MyString,"[a-zA-Z'-]")

\\\
Dim IsMatch As Boolean = _
Regex.IsMatch(<Input>, "^[a-zA-Z'-]*$")
///

You do not need to instantiate 'Regex' because 'IsMatch' is a shared method of the 'Regex' class.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

.



Relevant Pages

  • Re: regular expressions
    ... The hyphen is a special character in a set, you have to escape it: ... Function RegExpValidateas boolean ... Dim RegexObj as Regex = New Regex ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Compare a Variable Against Multiple Values
    ... Consider using OrElse instead of Or, as Or will cause all the equations to ... I would use the RegEx as its IMHO the "simplest" & "cleanest" ... wordsAs String) As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Compare a Variable Against Multiple Values
    ... you need to understand RegEx to be comfortable ... > the routine. ... > wordsAs String) As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Regular epressions with .net forward slash "/" character
    ... Can somone help with this regular expression problem VB sample below ... Dim RegexObj As Regex = New Regex ... forward slash seems not be working. ...
    (microsoft.public.dotnet.framework)