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
| 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 (?<!....).
'"\" =([^\\]|^)([\\])(?![\\])
'"/" =([^\/]|^)([\/])(?![\/])
'"*" =([^\*]|^)([\*])(?![\*])
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
MatchMsg = MatchMsg & "Correspondance trouvée """ & match.Submatches(1) & """ en position: " & match.FirstIndex + Len(match.SubMatches(0)) & vbCrLf
Next
'MsgBox MatchMsg
Else
MsgBox "Aucun match", 0, "VBScript RegExp Tester"
End If
strText = RegularExpressioN.Replace(strText, "$&")'"$1" "$&"
Set RegularExpressioN = Nothing
ReslutSpeciChars = strText
MsgBox TxtSource & vbCrLf & ReslutSpeciChars & vbCrLf & MatchMsg |
Partager