Run this program:
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Console.WriteLine(ReplaceText("p.x + p.y + p.z"))
Console.ReadLine()
End Sub
Public Function ReplaceText(ByVal sourceText As String) As String
Dim re As New Regex("[^\W_0-9A-Zp]")
Return re.Replace(sourceText, AddressOf MatchEval)
End Function
Private Function MatchEval(ByVal m As Match) As String
Return m.ToString.ToUpper
End Function
End Module
The output, as expected, is:
p.X + p.Y + p.Z
\W (note the capital "W") is the opposite of \w (lower case "w"). \w means
"word characters", so \W means "NON-word characters". \W will match things
like spaces and punctuation marks, but not letters, numbers, or the
underscore character.
\w = [a-zA-Z0-9_]
\W = [^a-zA-Z0-9_]
This means that the expression matches any character that is:
(a) not a NON-word character (double negative means that it must be a word
character - this is equivalent to \w, or [a-zA-Z0-9_])
(b) not an underscore (combined with (a) means [a-zA-Z0-9])
(c) not a number (combined with (a) and (b) means [a-zA-Z])
(d) not a capital letter (combined with (a), (b), and (c) means [a-z])
(e) not a "p" (combined with (a), (b), (c), and (d) means [a-z] and also
[^p] )
This, by definition, is any lower case letter other than "p".
Hope this clears things up,
Brian Davis
http://www.knowdotnet.com
cody said:
[^\W_0-9A-Zp] does in fact match "any lower case letter except the letter
'p'". Just try it and see. If you want to match every lower case letter
except the letter "a", then use [^\W_0-9A-Za]. If you want to match every
lower case letter except the letters "a" and "p", then use
[^\W_0-9A-Zap]...etc.
No. [^\W_0-9A-Zp] matches nothing. if simply says "Match all characters
except: word characters, underscores, characters in the range 0-9 and
characters in the range A-Z and p": I tried is and it matches nothing. How
should it? Everything in brackets is together one characterclass, negated by
the ^ character.
--
cody
[Freeware, Games and Humor]
www.deutronium.de.vu ||
www.deutronium.tk