Salut
Petit programme pour faire des essais Pattern de l'objet RegExp. avec HTA ---> VBScript
Le programme à lancer (enregistrer sous le nom EtudeRegExp.hta)
Pièce jointe 224165Code:
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178 <HTML> <HEAD lang="fr"> <title> Etude Pattern de l'objet RegExp </title> <HTA:APPLICATION id="EtudeRegExp" applicationname="EtudeRegExp" version="1" SCROLL="no" BorderStyle="normal" > </HEAD> <SCRIPT language="VBScript" type="text/vbscript"> '------------------------------------------------------------------------------------------------------------------ '*** variables public *** Dim BarT, DblBord, DossierRacineDuProg '------------------------------------------------------------------------------------------------------------------ Sub Window_Onload() Dim Bord MoveTo -Screen.availWidth,-Screen.availHeight 'place la page HTA hors de l'écran ResizeTo Screen.availWidth,Screen.availHeight ' Agrandi la page HTA au maximum de la grandeur disponnible du burreau Bord = screenLeft + Screen.availWidth ' Calcul de l'épaisseur du cadre de la fenêtre HTA DblBord = Bord*2 BarT = (screenTop + Screen.availHeight) - Bord ' Calcule de l'hauteur de la barre de titre de la fenêtre HTA ResizeTo 490,535 ' dimensionne la fenêtre HTA (largeur, hauteur) MoveTo (Screen.availWidth-490)/2,(Screen.availHeight - 535) / 2 ' Centrage de la fenêtre HTA sur le burreeau Dim ChemNomComplet ChemNomComplet = EtudeRegExp.CommandLine ' ChemNomComplet = Id du programme.CommandLine DossierRacineDuProg = Left(ChemNomComplet, (InStrRev(ChemNomComplet, "\", -1, vbTextCompare))) DossierRacineDuProg = Replace(DossierRacineDuProg,Chr(34),"") End Sub '---------------------------------------------------------------------------------------------------------------------- Sub Window_OnResize() If document.body.offsetWidth >= 474 Then CartoucheHaut.Style.width = document.body.offsetWidth CartoucheMil.Style.width = document.body.offsetWidth TextPattern.Style.width = document.body.offsetWidth - 10 BtAide.Style.Left = CvI(TextPattern.Style.width) - CvI(BtAide.Style.Width) + 4 TextSoumis.Style.Width = TextPattern.Style.Width TextReplace.Style.Width = TextPattern.Style.Width TextResult.Style.Width = TextPattern.Style.Width Else ResizeTo 474 + DblBord, document.body.offsetHeight + DblBord + BarT End If If document.body.offsetHeight >= 497 Then Dim Hpage, Hcart1, Hcart2, HcatS, MiHaut Hpage = CvI(document.body.offsetHeight) Hcart1 = CvI(CartoucheHaut.Style.Height) Hcart2 = CvI(CartoucheMil.Style.Height) HcatS = Hcart1 + Hcart2 MiHaut = (Hpage - HcatS)/2 TextSoumis.Style.Height = MiHaut TextResult.Style.Height = MiHaut - 4 CartoucheMil.Style.Top = CvI(TextSoumis.Style.Top) + CvI(TextSoumis.Style.Height) TextResult.Style.Top = CvI(CartoucheMil.Style.Top) + CvI(CartoucheMil.Style.Height) Else ResizeTo document.body.offsetWidth + DblBord, 497 + DblBord + BarT End If End Sub '---------------------------------------------------------------------------------------------------------------------- Function CvI(literal) Literal = Trim(literal) If Instr(literal,"px") Then CvI = Cint(Left(literal, Len(Literal)-2)) Else CvI = Cint(literal) End Function '---------------------------------------------------------------------------------------------------------------------- Sub BtGoClick() Dim RegularExpressioN, ResulT, Match Dim MeStr, MsG, Cpt TextResult.innertext = "": MsG = "": Cpt = 0: MeStr = TextSoumis.Value Set RegularExpressioN = New RegExp RegularExpressioN.Pattern = TextPattern.Value 'distinction caract. min/MAJ ou accepte caract. min/MAJ If DistinminMAJ(0).CHECKED Then RegularExpressioN.IgnoreCase = False Else RegularExpressioN.IgnoreCase = True 'prend fin à la premiére ocurence trouvée ou s'applique à la chaîne entière If DebFinOcur(0).CHECKED Then RegularExpressioN.Global = False Else RegularExpressioN.Global = True If Metode(2).CHECKED Then ' méthode Test simple If RegularExpressioN.Test(MeStr) = True Then TextResult.innertext = "méthode test: " & vbNewLine & "au moins une correspondance trouvée" Else TextResult.innertext = "méthode test: " & vbNewLine & "aucune correspondance trouvée" End If Exit Sub End If If Metode(0).CHECKED Then 'méthode Execute If RegularExpressioN.Test(MeStr) = True Then 'non obligatoire (précotion), méthode Test Set ResulT = RegularExpressioN.Execute(MeStr) For Each Match In ResulT MsG = MsG & "position: " & Match.FirstIndex & " Longueur: " & Match.Length & " Valeur: " & Match.Value Cpt = Cpt + 1 If Cpt <> 0 Then MsG = MsG & vbNewLine Next MsG = "Nbr.d'occurence: " & ResulT.Count & vbNewLine & MsG Set Match = Nothing Else MsG = "Pas d'occurence" End If Else 'méthode Replace MsG = RegularExpressioN.Replace(MeStr, TextReplace.innertext) ' Effectue le remplacement If MsG = MeStr Then MsG = "Pas d'occurence, pas de remplacement " & vbNewLine & MsG Set ResulT = Nothing End If Set RegularExpressioN = Nothing TextResult.innertext = MsG End Sub '---------------------------------------------------------------------------------------------------------------------- Sub GoAide() Dim WSH, Cmd, ChemNomHta ChemNomHta = chr(34) & DossierRacineDuProg & "AideEtudeRegExp.hta" & chr(34) Set WSH = CreateObject("WScript.Shell") Cmd = "Mshta.exe " & ChemNomHta WSH.Run Cmd, 1, true Set WSH= nothing End Sub '---------------------------------------------------------------------------------------------------------------------- </SCRIPT> <body style=" background-color:#FFFFA8"> <!-- Partie Pattern --------------------------------------------------------------------- --> <fieldset Name="CartoucheHaut" id="CartoucheHaut" style="border:none; position: absolute; left:0px; top:0px; height:55px; width:472px; background-color:#DDFFB3"> <Div id="DivPattern" style="position:absolute; left:0px; top:2px; height:13px; width:42px"> Pattern </Div> <Input Type="button" id="BtAide" name="BtAide" Value="Aide rédaction Pattern" onClick="GoAide" style="position:absolute; left:4px; top:0px; height:20px; width:150px; Color:#000000; background-Color:#BBBBBF "> <INPUT Type="text" id="TextPattern" name="TextPattern" value="C" style="border-style: solid; position: absolute; left:4px; top: 20px; height:19px; width:463px" > <!-- Partie Texte soumis --------------------------------------------------------------------- --> <Div id="DivTextSoumis" style="position:absolute; left:0px; top:37px; height:13px; width:100px"> Texte soumis </Div> </fieldset> <TEXTAREA name="TextSoumis" Value ="" style="border-style: solid; position: absolute; left:4px; top: 55px; height:133px; width:463px"> Coucou, c'est moi, pour une petite experience </TEXTAREA> <fieldset Name="CartoucheMil" id="CartoucheMil" style="border:none; position: absolute; left:0px; top:188px; height:170px; width:472px; background-color:#FFFFA8"> <!-- Partie Replace --------------------------------------------------------------------- --> <Div id="DivTextReplace" style="position:absolute; left:0px; top:0px; height:13px; width:364px"> Texte de remplacement pour méthode Replace </Div> <TEXTAREA name="TextReplace" Value ="" style="border-style: solid; position: absolute; left:4px; top:19px; height:35px; width:463px">Ch</TEXTAREA> <!-- Partie options --------------------------------------------------------------------- --> <Div id="DivDistinminMAJ" style="position:absolute; left:2px; top:55px; height:13px; width:364px"> |------------ (Valeur par défaut) -----------| </Div> <INPUT Type="radio" id="DistinminMAJ0" name="DistinminMAJ" value="" CHECKED style="position: absolute; left:2px; top:75px; height:13px; width:13px" > <label for="DistinminMAJ0" style="position:absolute; left:17px; top:71px; height:13px; width:364px"> distinction caract. min/MAJ </label> <INPUT Type="radio" id="DistinminMAJ1" name="DistinminMAJ" value="" style="position: absolute; left:280px; top:75px; height:13px; width:13px" > <label for="DistinminMAJ1" style="position:absolute; left:295px; top:71px; height:13px; width:364px"> accepte caract. min/MAJ </label> <!-- --------------------------------------------------------------------- --> <INPUT Type="radio" id="DebFinOcur0" name="DebFinOcur" value="" CHECKED style="position: absolute; left:2px; top:91px; height:13px; width:13px" > <label for="DebFinOcur0" style="position:absolute; left:17px; top:87px; height:13px; width:364px"> prend fin à la premiére ocurence trouvée </label> <INPUT Type="radio" id="DebFinOcur1" name="DebFinOcur" value="" style="position: absolute; left:280px; top:91px; height:13px; width:13px" > <label for="DebFinOcur1" style="position:absolute; left:295px; top:87px; height:13px; width:364px"> s'applique à la chaîne entière </label> <!-- Partie methodes --------------------------------------------------------------------- --> <INPUT Type="radio" id="Metode0" name="Metode" value="" CHECKED style="position: absolute; left:2px; top:122px; height:13px; width:13px; background-Color:#0031FF" > <label for="Metode0" style="position:absolute; left:17px; top:118px; height:13px; width:364px; Color:#0031FF;"> méthode Execute </label> <INPUT Type="radio" id="Metode1" name="Metode" value="" style="position: absolute; left:140px; top:122px; height:13px; width:13px; background-Color:#0031FF" > <label for="Metode1" style="position:absolute; left:155px; top:118px; height:13px; width:364px; Color:#0031FF;"> méthode Replace </label> <INPUT Type="radio" id="Metode2" name="Metode" value="" style="position: absolute; left:280px; top:122px; height:13px; width:13px; background-Color:#0031FF" > <label for="Metode2" style="position:absolute; left:295px; top:118px; height:13px; width:364px; Color:#0031FF;"> méthode Test </label> <!-- Partie Go resultat --------------------------------------------------------------------- --> <Input Type="button" id="BtGo" name="BtGo" Value="Go" onClick="BtGoClick" style="position:absolute; left:4px; top:146px; height:25px; width:130px; Color:#000000; background-Color:#BBBBBF "> <Div id="DivTextResult" style="position:absolute; left:138px; top:152px; height:13px; width:200px"> Resultat </Div> </fieldset> <TEXTAREA id="TextResult" name="TextResult" Value ="" style="border-style: solid; position: absolute; left:4px; top: 360px; height:133px; width:463px"> </TEXTAREA> </body> </HTML>
Le programme d'aide qui peut être lancé seul ou depuis le HTA si dessus.(enregistrer sous le nom AideEtudeRegExp.hta)
Il existe une version VB6 et anterieur ICICode:
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 <HTML> <HEAD lang="fr"> <title> Aide rédaction Pattern de l'objet RegExp </title> <HTA:APPLICATION id="AideEtudeRegExp" applicationname="AideEtudeRegExp" version="1" SCROLL="no" BorderStyle="normal" > </HEAD> <SCRIPT language="VBScript" type="text/vbscript"> '------------------------------------------------------------------------------------------------------------------ Sub Window_Onload() ResizeTo 1223,787 ' dimensionne la fenêtre HTA (largeur, hauteur) MoveTo (Screen.availWidth-1223)/2,(Screen.availHeight - 787) / 2 ' Centrage de la fenêtre HTA sur le burreeau End Sub '------------------------------------------------------------------------------------------------------------------ </SCRIPT> <body style="font-family:Courier, MS Sans Serif, Arial, Verdana, serif; font-size=12px; font-weight:bold; background-color:#FFFFD2" > \     Marque le caractère suivant comme caractère spécial ou littéral. Par exemple, "n" correspond au caractère "n". "\n" correspond à un caractère de nouvelle ligne. <br>         La séquence "\\" correspond à "\", tandis que "\(" correspond à "(". <br> ^     Correspond au début de la saisie. <br> $     Correspond à la fin de la saisie. <br> *     Correspond au caractère précédent zéro fois ou plusieurs fois. Ainsi, "zo*" correspond à "z" ou à "zoo". <br> +     Correspond au caractère précédent une ou plusieurs fois. Ainsi, "zo+" correspond à "zoo", mais pas à "z". <br> ?     Correspond au caractère précédent zéro ou une fois. Par exemple, "a?ve?" correspond à "ve" dans "lever". <br> .     Correspond à tout caractère unique, sauf le caractère de nouvelle ligne. <br> (modèle)     Recherche le modèle et mémorise la correspondance. La sous-chaîne correspondante peut être extraite de la collection Matches obtenue, <br>         à l'aide d'Item [0]...[n]. Pour trouver des correspondances avec des caractères entre parenthèses ( ), utilisez "\(" ou "\)". <br> x|y     Correspond soit à x soit à y. Par exemple, "z|foot" correspond à "z" ou à "foot". "(z|f)oo" correspond à "zoo" ou à "foo". <br> {n}     n est un nombre entier non négatif. Correspond exactement à n fois le caractère. Par exemple, "o{2}" ne correspond pas à "o" dans "Bob," <br>         mais aux deux premiers "o" dans "fooooot". <br> {n,}     n est un entier non négatif. Correspond à au moins n fois le caractère. Par exemple, "o{2,}" ne correspond pas à "o" dans "Bob", <br>         mais à tous les "o" dans "fooooot". "o{1,}" équivaut à "o+" et "o{0,}" équivaut à "o*". <br> {n,m}     m et n sont des entiers non négatifs. Correspond à au moins n et à au plus m fois le caractère. Par exemple, <br>         "o{1,3}" correspond aux trois premiers "o" dans "foooooot" et "o{0,1}" équivaut à "o?". <br> [xyz]     Jeu de caractères. Correspond à l'un des caractères indiqués. Par exemple, "[abc]" correspond à "a" dans "plat". <br> [^xyz]     Jeu de caractères négatif. Correspond à tout caractère non indiqué. Par exemple, "[^abc]" correspond à "p" dans "plat". <br> [a-z]     Plage de caractères. Correspond à tout caractère dans la série spécifiée. Par exemple, <br>         "[a-z]" correspond à tout caractère alphabétique minuscule compris entre "a" et "z". <br> [^m-z]     Plage de caractères négative. Correspond à tout caractère ne se trouvant pas dans la série spécifiée. Par exemple, <br>         "[^m-z]" correspond à tout caractère ne se trouvant pas entre "m" et "z". <br> \b     Correspond à une limite représentant un mot, autrement dit, à la position entre un mot et un espace. Par exemple, <br>         "er\b" correspond à "er" dans "lever", mais pas à "er" dans "verbe". <br> \B     Correspond à une limite ne représentant pas un mot. "en*t\B" correspond à "ent" dans "bien entendu". <br> \d     Correspond à un caractère représentant un chiffre. Équivaut à [0-9]. <br> \D     Correspond à un caractère ne représentant pas un chiffre. Équivaut à [^0-9]. <br> \f     Correspond à un caractère de saut de page. <br> \n     Correspond à un caractère de nouvelle ligne. <br> \r     Correspond à un caractère de retour chariot. <br> \s     Correspond à tout espace blanc, y compris l'espace, la tabulation, le saut de page, etc. Équivaut à "[ \f\n\r\t\v]". <br> \S     Correspond à tout caractère d'espace non blanc. Équivaut à "[^ \f\n\r\t\v]". <br> \t     Correspond à un caractère de tabulation. <br> \v     Correspond à un caractère de tabulation verticale. <br> \w     Correspond à tout caractère représentant un mot et incluant un trait de soulignement. Équivaut à "[A-Za-z0-9_]". <br> \W     Correspond à tout caractère ne représentant pas un mot. Équivaut à "[^A-Za-z0-9_]". <br> \num     Correspond à num, où num est un entier positif. Fait référence aux correspondances mémorisées. Par exemple, <br>        "(.)\1" correspond à deux caractères identiques consécutifs. <br> \n    Correspond à n, où n est une valeur d'échappement octale. Les valeurs d'échappement octales doivent comprendre 1, 2 ou 3 chiffres. Par exemple, <br>        "\11" et "\011" correspondent tous les deux à un caractère de tabulation. "\0011" équivaut à "\001" & "1". <br>        Les valeurs d'échappement octales ne doivent pas excéder 256. <br>        Si c'était le cas, seuls les deux premiers chiffres seraient pris en compte dans l'expression. Permet d'utiliser les codes ASCII dans des expressions régulières. <br> \xn    Correspond à n, où n est une valeur d'échappement hexadécimale. Les valeurs d'échappement hexadécimales doivent comprendre deux chiffres obligatoirement. <br>        Par exemple, "\x41" correspond à "A". "\x041" équivaut à "\x04" & "1". Permet d'utiliser les codes ASCII dans des expressions régulières. <br> </body> </HTML>