Re: reg expression by JHP
JHP
Thu Jan 26 14:30:38 CST 2006
Try this:
Option Explicit
Dim objRegEx, strLine, objMatches, strMatch
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "[^a-z,^A-Z]"
strLine = "1%3a4*D8fg9"
Set objMatches = objRegEx.Execute(strLine)
If objMatches.Count > 0 Then
For Each strMatch in objMatches
WScript.Echo strMatch.Value
Next
End If
Set objMatches = Nothing
Set objRegEx = Nothing
Here are the various 'Character Usage':
* Matches the previous character zero or more times
+ Matches the previous character one or more times
? Matches the previous character zero or one times
. Matches any single character except the newline
^ Matches the start of the input
$ Matches the end of the input
x|y Matches either first or second character listed
(pattern) Matches pattern
{number} Matches exactly number times
{number,} Matches number, or more, times (note comma)
{num1, num2} Matches at least num1 and at most num2 times
[abc] Matches any character listed between the [ ]
[^abc] Matches all characters except those listed between the [ ]
[a-e] Matches any characters in the specified range (a,b,c,d,e)
[^K-Q] Matches all characters except in the specified range
\ Signifies that the next character is special or a literal.
\b Matches only on a word boundary
\B Matches only inside a word
\d Matches only on a digit
\D Matches only on a non-digit
\f Matches only on a form feed character
\n Matches only on a new line
\r Matches only on a carriage return
\s Matches only on a blank space
\S Matches only on nonblank spaces
\t Matches only on a tab
\v Matches only on a vertical tab
\w Matches only on A to Z, a to z, 0 to 9, and _
\W Matches characters other than A to Z, a to z, 0 to 9, and _
\number Matches any positive number
\octal Matches any octal number
\xhex Matches any hexadecimal number (x is required)
"Star" <momo2804@gmail.com> wrote in message
news:1138293786.951167.150060@g49g2000cwa.googlegroups.com...
> I'm trying to write an script that does a check of each line in a text
> file for all non-alphabetic characters....... I know it can be done
> using the reg exp.....
>
> can anyone provide some examples of how this can be done........I have
> a look through some but they all seem so complicated and I haven't done
> much scripting in this area...........
>
>
> thaks in advance
>