Expression régulière

freelance28 Messages postés 3 Date d'inscription mercredi 13 mai 2009 Statut Membre Dernière intervention 4 novembre 2022 - Modifié le 3 nov. 2022 à 09:23
Whismeril Messages postés 19029 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 26 avril 2024 - 5 nov. 2022 à 07:01

Bonjour,

Pour une réécriture d'url, j'aimerai pouvoir vérifier que l'url est de la forme :

XXXXX/nom-de-la-ville/repertoire/ où XXXXX est le code postal de la ville.

Pour l'instant, j'en suis à ^[0-9]{5}/(([A-Za-z0-9]|-)+)/repertoire/$ mais je n'arrive pas à me retourner le code postal comme je peux le tester sur https://regex101.com/

Ainsi l'url 28100/dreux/repertoire/ me renvoit :

[ { "content": "28100/dreux/repertoire/", "isParticipating": true, "groupNum": 0, "startPos": 0, "endPos": 23 }, { "content": "0", "isParticipating": true, "groupNum": 1, "startPos": 4, "endPos": 5 }, { "content": "dreux", "isParticipating": true, "groupNum": 2, "startPos": 6, "endPos": 11 }, { "content": "x", "isParticipating": true, "groupNum": 3, "startPos": 10, "endPos": 11 } ] ]

Auriez-vous une idée ?

Merci d'avance !


2 réponses

Whismeril Messages postés 19029 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 26 avril 2024 656
3 nov. 2022 à 23:08

Bonsoir 

est ce que c'est ça que tu veux https://regex101.com/r/TOqAlQ/1


0
freelance28 Messages postés 3 Date d'inscription mercredi 13 mai 2009 Statut Membre Dernière intervention 4 novembre 2022
4 nov. 2022 à 08:28

J'ai trouvé, c'était une histoire de parenthèses :

^([0-9]{5})\/(([A-Za-z0-9]|-)+)\/repertoire\/$


0
Whismeril Messages postés 19029 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 26 avril 2024 656
5 nov. 2022 à 07:01

Sauf que ta seconde regex  (tout comme la première) ne retourne rien dans 

[ { "content": "28100/dreux/repertoire/", "isParticipating": true, "groupNum": 0, "startPos": 0, "endPos": 23 }, { "content": "0", "isParticipating": true, "groupNum": 1, "startPos": 4, "endPos": 5 }, { "content": "dreux", "isParticipating": true, "groupNum": 2, "startPos": 6, "endPos": 11 }, { "content": "x", "isParticipating": true, "groupNum": 3, "startPos": 10, "endPos": 11 } ] ]

0
Rejoignez-nous