Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expressions in VB

Status
Not open for further replies.

lpatnaik

Programmer
Jul 11, 2002
53
0
0
Hi,
How can I implement the regular expressions in VB in a way so that the result set gives me all the invalid characters in a word.

To explain:
I have a word "ABC%DEF~GHI^JKL#MNO"
I want to find out what all invalid characters are there in the word, given that "%", "~" and "#" are invalid.

The following code, only returns the first inalid character in list.
Dim reg As New RegExp
Dim strTest As String
Dim regPattern As String
Dim Matches As MatchCollection
Dim mtch As Match

Dim blnFound As Boolean

strTest = "ashasd^$%@$~@#@Q%~$#"
regPattern = &quot;\[%^<>#\]?\[]&quot;

With reg
.Pattern = regPattern
If .Test(strTest) = True Then
Set Matches = .Execute(strTest)

For Each mtch In Matches
MsgBox mtch.Value
Next mtch
ValidateManuOrdID = True
End If
End With
Set reg = Nothing

Please reply ASAP
 
Did you try setting the .Global propety of the RegExp to True? Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi,

It is probally better to set Pattern to &quot;\W&quot; (that is [^A-Za-z0-9_] )

Also if you set Global to true it will match all occurances of the expression instead of just the first.

Hope this helps.

Rich.
 
[tt]
' Returns a string containing all non-alphas (presumed 'bad') in strTest
Private Function BadChars(strTest As String) As String
Dim re As New RegExp

With re
.Global = True
.Pattern = &quot;(\w)&quot;
BadChars = .Replace(strTest, &quot;&quot;)
End With

Set re = Nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top