Version imprimable du sujet

Cliquez ici pour voir ce sujet dans son format original

Forums MacBidouille _ Les Langages Du Web _ Résolu: JavaScript et expression régulière sur chaîne

Écrit par : clarusad 26 Nov 2021, 12:59

Salut, je souhaiterais transformer un adresse mac en une seule fonction. Est ce possible en JS ?
Je récupère ça par exemple
80-91-33-d2-cc-0b
Et je voudrais la même chose sans les tirets.

Merci

Écrit par : Jaypee 27 Nov 2021, 09:30

Si vous êtes dans Safari, dans le menu Développement, choisissez 'Afficher l'inspecteur Web', et tout en bas de l'écran il y a une ligne qui accepte des commandes.
Tapez:

Code
console.log('aa-bb-cc-dd-ee'.replaceAll('-',''))


Et vous aurez le résultat voulu.

JP

Écrit par : clarusad 27 Nov 2021, 10:10

Citation (Jaypee @ 27 Nov 2021, 09:30) *
Et vous aurez le résultat voulu.

Rhooo c'était pourtant si simple !
Merci Jaypee. Je teste ça dès lundi avant de clôturer ce fil.

Pour celles et ceux que ça intéresse, le fond de l'histoire est de modifier un formulaire, que j'utilise des dizaines de fois par jour, dans lequel je colle une mac. Pour faire cela j'utilise Tampermonkey sous Firefox.
https://addons.mozilla.org/fr/firefox/addon/tampermonkey/

Écrit par : ethanklein 3 Feb 2023, 08:44

If the string doesn't match the regular expression, you can use the test() method on the regular expression to determine whether it does. The string to test against the pattern is the only parameter accepted by the test() method. If the string does or does not match the regular expression, a Boolean value is returned.

Écrit par : baron 3 Feb 2023, 20:43

Citation (ethanklein @ 3 Feb 2023, 08:44) *
If the string doesn't match the regular expression, you can use the test() method on the regular expression to determine whether it does. The string to test against the pattern is the only parameter accepted by the test() method. If the string does or does not match the regular expression, a Boolean value is returned.

Merci pour ta réponse.
Néanmoins, ce sont ici des forums francophones où chacun est invité à s'exprimer en bon français.

Traduction rapide (mais je ne suis pas sûr d'avoir tout bien compris…) :
Citation
Si la chaîne ne correspond pas à l'expression régulière, vous pouvez utiliser la méthode test() sur l'expression régulière pour déterminer si elle y correspond. La chaîne à tester par rapport au motif est le seul paramètre accepté par la méthode test(). Une valeur booléenne est renvoyée selon que la chaîne correspond ou non à l'expression régulière.

Propulsé par Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)