Académique Documents
Professionnel Documents
Culture Documents
Syntaxe :
/modele/modificateurs;
Exemple :
Les Modificateurs :
Modificateur Action
i Respect de la case :
i = casse insensible,
par défaut = casse sensible.
g Recherche globale (sur toute la chaîne, pas seulement la
première occurrence = global search).
m Correspondance (match) multiligne.
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-X
Expression Signification
console.log(reDate);
console.log(match);
console.log(jour);
console.log(mois);
console.log(an);
console.log(jourx);
</script>
console.log(reDate);
console.log(match);
console.log(jour);
console.log(
date.replace(reDate, '$<jour>-$<mois>-$<an>')
); // Changement format de date.
</script>
Firefox :
console.log( match[1] );
</script>
Le dernier nombre :
console.log(`match["index"] = ${match["index"]}`);
// match["index"] = 0
console.log('match["length"] =',match["length"]);
// match["length"] = 2
console.log("match.length =",match.length);
// match.length = 2
console.log("match['input'] =",match['input']);
// match['input'] = Mon IP : 123.45.73.255
console.log("match[0] =",match[0]);
// match[0] = Mon IP : 123.45.73.255
console.log("match[2] =",match[2]);
// match[2] = undefined
console.log("match[3] =",match[3]);
// match[3] = undefined
console.log("match[4] =",match[4]);
// match[4] = undefined
console.log("match[5] =",match[5]);
// match[5] = undefined
</script>
Le premier nombre :
console.log("match =",match);
// match =
// Array [ "Mon IP : 123.45.73.255", "255" ]
console.log(`match["index"] = ${match["index"]}`);
RegExp - 7 / 23 - jeudi, 20. décembre 2018 (10:05 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-X
// match["index"] = 0
console.log('match["length"] =',match["length"]);
// match["length"] = 2
console.log("match.length =",match.length);
// match.length = 2
console.log("match['input'] =",match['input']);
// match['input'] = Mon IP : 123.45.73.255
console.log("match[0] =",match[0]);
// match[0] = Mon IP : 123.45.73.255
console.log("match[2] =",match[2]);
// match[2] = undefined
console.log("match[3] =",match[3]);
// match[3] = undefined
console.log("match[4] =",match[4]);
// match[4] = undefined
console.log("match[5] =",match[5]);
// match[5] = undefined
</script>
match = reLookahead.exec(
'Mon IP : 123.45.73.255');
console.log("match =",match);
// match =
// Array [ "Mon IP : 123", "123" ]
console.log(`match["index"] = ${match["index"]}`);
// match["index"] = 0
console.log('match["length"] =',match["length"]);
// match["length"] = 2
console.log("match['input'] =",match['input']);
// match['input'] = Mon IP : 123.45.73.255
console.log("match[0] =",match[0]);
// match[0] = Mon IP : 123
console.log("match[2] =",match[2]);
// match[2] = undefined
console.log("match[3] =",match[3]);
// match[3] = undefined
console.log("match[4] =",match[4]);
// match[4] = undefined
console.log("match[5] =",match[5]);
// match[5] = undefined
</script>
match = reLookahead.exec(
'Mon IP : 123.45.73.255');
console.log("match =",match);
// match =
// Array [ "Mon IP : 123", "123" ]
console.log(`match["index"] = ${match["index"]}`);
// match["index"] = 0
console.log('match["length"] =',match["length"]);
// match["length"] = 2
console.log("match.length =",match.length);
// match.length = 2
console.log("match['input'] =",match['input']);
// match['input'] = Mon IP : 123.45.73.255
RegExp - 9 / 23 - jeudi, 20. décembre 2018 (10:05 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-X
console.log("match[0] =",match[0]);
// match[0] = Mon IP : 123
console.log("match[2] =",match[2]);
// match[2] = undefined
console.log("match[3] =",match[3]);
// match[3] = undefined
console.log("match[4] =",match[4]);
// match[4] = undefined
console.log("match[5] =",match[5]);
// match[5] = undefined
</script>
// reLookahead = /\D+.(.\d+)/, // ou
reLookahead = /\D+.(\d{3})+/,
match = reLookahead.exec(
'Mon IP : 123.45.73.255');
console.log("match =",match);
// match =
// Array [ "Mon IP : 123", "23" ]
console.log(`match["index"] = ${match["index"]}`);
// match["index"] = 0
console.log('match["length"] =',match["length"]);
// match["length"] = 2
console.log("match.length =",match.length);
// match.length = 2
console.log("match['input'] =",match['input']);
// match['input'] = Mon IP : 123.45.73.255
RegExp - 10 / 23 - jeudi, 20. décembre 2018 (10:05 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-X
console.log("match[0] =",match[0]);
// match[0] = Mon IP : 123
console.log("match[1] =",match[1]);
// match[1] = 123
console.log("match[2] =",match[2]);
// match[2] = undefined
console.log("match[3] =",match[3]);
// match[3] = undefined
console.log("match[4] =",match[4]);
// match[4] = undefined
console.log("match[5] =",match[5]);
// match[5] = undefined
</script>
vs
// reLookahead = /\D+.(.\d+)/, // ou
reLookahead = /\D+.(\d+)+/,
match = reLookahead.exec(
'Mon IP : 123.45.73.255');
console.log("match =",match);
// match =
// Array [ "Mon IP : 123", "23" ]
console.log(`match["index"] = ${match["index"]}`);
// match["index"] = 0
console.log('match["length"] =',match["length"]);
// match["length"] = 2
console.log("match.length =",match.length);
// match.length = 2
console.log("match['input'] =",match['input']);
// match['input'] = Mon IP : 123.45.73.255
RegExp - 11 / 23 - jeudi, 20. décembre 2018 (10:05 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-X
console.log("match[0] =",match[0]);
// match[0] = Mon IP : 23
console.log("match[1] =",match[1]);
// match[1] = 23
console.log("match[2] =",match[2]);
// match[2] = undefined
console.log("match[3] =",match[3]);
// match[3] = undefined
console.log("match[4] =",match[4]);
// match[4] = undefined
console.log("match[5] =",match[5]);
// match[5] = undefined
</script>
LookBehind :
Par exemple, extraire le prix sans le sigle monétaire : Sautez les non-
digits et prendre les premiers digits avant d’autres non-digits. À ne pas
confondre avec un éventuel « LookReverse », ici c’est « sauter » : « re-
garder après… » ou « lookPast… ».
console.log( match[1] );
</script>
console.log( match[1] ); // $
</script>
« Parser » le IP :
Les Métacaractères :
Itérateur Signification
Propriété Description
Méthode Description
compile() Compile une expression régulière (Dépréciée dans la version 1.5).
exec() Teste un match dans une chaîne. Renvoie le premier match
test() Teste un match dans une chaîne. Renvoie true ou false
toString() Renvoie la valeur de la chaîne de l’expression régulière
Propriétés de RegExp :
<script>
console.log(RegExp.prototype);
</script>
Exécution :
1 {constructor: ƒ, exec: ƒ, …}
A compile:ƒ compile()
B constructor:ƒ RegExp()
C dotAll:(...)
D exec:ƒ exec()
E flags:(...)
F global:(...)
G ignoreCase:(...)
H multiline:(...)
I source:(...)
RegExp - 20 / 23 - jeudi, 20. décembre 2018 (10:05 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-X
J sticky:(...)
K test:ƒ test()
L toString:ƒ toString()
M unicode:(...)
N Symbol(Symbol.match):ƒ [Symbol.match]()
O Symbol(Symbol.replace):ƒ [Symbol.replace]()
P Symbol(Symbol.search):ƒ [Symbol.search]()
Q Symbol(Symbol.split):ƒ [Symbol.split]()
R get dotAll:ƒ dotAll()
S get flags:ƒ flags()
T get global:ƒ global()
U get ignoreCase:ƒ ignoreCase()
V get multiline:ƒ multiline()
W get source:ƒ source()
X get sticky:ƒ sticky()
Y get unicode:ƒ unicode()
Z __proto__:Object
0: "input"
1: "lastMatch"
2: "lastParen"
3: "leftContext"
4: "rightContext"
5: "$1"
6: "$2"
7: "$3"
8: "$4"
9: "$5"
10: "$6"
11: "$7"
12: "$8"
13: "$9"
14: "$_"
15: "$&"
16: "$+"
17: "$`"
RegExp - 21 / 23 - jeudi, 20. décembre 2018 (10:05 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-X
18: "$'"
19: "prototype"
20: "length"
21: "name"
length: 22
__proto__: Array []
Mots-clés :
diasfb@mail2world.com