1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| TxtSource = "\-\\\*-****/Un test, Pourquoi faire? c'est fou ça! \****-*/// /"
ReslutSpeciChars = ""
Dim strText, RegularExpressioN
'([^\,]|^)([\,])(?![\,])
'[^\,] = n'est pas une virgule.
'| = ou.
'^ = est au début de la chaîne.
'(?![\,]) = n'est pas suivit d'une virgule.
'Equivalent a (?<![\,])[\,](?![\,]) soit (pas de virgule avant, pas de virgule après), mais non supporter par vb (test arrière (?<!....).
'(\?)|(\!)|(\:)|(\;)|(\,)|(\')|(\&)|(\~)|(\{)|(\})|(\()|(\))|(\[)|(\])|(\@)|(\^)|(\¨)|(\$)|(\£)|(\)|(\.)|(\<)|(\>)|(\|)
'"\" =([^\\]|^)([\\])(?![\\]) '"&" =([^\&]|^)([\&])(?![\&]) "£" =([^\£]|^)([\£])(?![\£])
'"/" =([^\/]|^)([\/])(?![\/]) '"~" =([^\~]|^)([\~])(?![\~]) "" =([^\]|^)([\])(?![\])
'"*" =([^\*]|^)([\*])(?![\*]) '"{" =([^\{]|^)([\{])(?![\{]) "." =([^\.]|^)([\.])(?![\.])
'"+" =([^\+]|^)([\+])(?![\+]) '"}" =([^\}]|^)([\}])(?![\}]) "<" =([^\<]|^)([\<])(?![\<])
'"-" =([^\-]|^)([\-])(?![\-]) '"(" =([^\(]|^)([\(])(?![\(]) ">" =([^\>]|^)([\>])(?![\>])
'"=" =([^\=]|^)([\=])(?![\=]) '")" =([^\)]|^)([\)])(?![\)]) "|" =([^\|]|^)([\|])(?![\|])
'"?" =([^\?]|^)([\?])(?![\?]) '"[" =([^\[]|^)([\[])(?![\[])
'"!" =([^\!]|^)([\!])(?![\!]) '"]" =([^\]]|^)([\]])(?![\]])
'":" =([^\:]|^)([\:])(?![\:]) '"@" =([^\@]|^)([\@])(?![\@])
'";" =([^\;]|^)([\;])(?![\;]) '"^" =([^\^]|^)([\^])(?![\^])
'"," =([^\,]|^)([\,])(?![\,]) '"¨" =([^\¨]|^)([\¨])(?![\¨])
'"'" =([^\']|^)([\'])(?![\']) '"$" =([^\$]|^)([\$])(?![\$])
' Char | char | char
FindSpeciChars = "([^\\]|^)([\\])(?![\\])|([^\/]|^)([\/])(?![\/])|([^\*]|^)([\*])(?![\*])" _
& "|([^\-]|^)([\-])(?![\-])"
strText = TxtSource
Set RegularExpressioN = New RegExp
RegularExpressioN.Pattern = FindSpeciChars
RegularExpressioN.Global = True
Set Matches = RegularExpressioN.Execute(strText)
If Matches.Count > 0 Then
MatchMsg = Matches.Count & " correspondance(s) trouvée(s)." & vbCRLF
For Each Match In Matches
For i = 1 To match.SubMatches.Count - 1 Step 2
If Not (match.SubMatches(i) = "") Then
MatchMsg = MatchMsg & "Correspondance trouvée """ & match.Submatches(i) & """ en position: " & match.FirstIndex + Len(match.Value) - 1 & vbCrLf
Next
Next
'MsgBox MatchMsg
Else
MsgBox "Aucun match", 0, "VBScript RegExp Tester"
End If
strText = RegularExpressioN.Replace(strText, "($&)") 'Parenthèses pour aider à la localisation des caractères remplacés.
Set RegularExpressioN = Nothing
ReslutSpeciChars = strText
MsgBox TxtSource & vbCrLf & ReslutSpeciChars & vbCrLf & MatchMsg |
Partager