# Learn Regex [Regex Learn - Regex Interactive Course](https://regexlearn.com/learn) ➝ [Regex 101 - EN](https://regexlearn.com/learn/regex101) [Regular Expression Language - Quick Reference | Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference) https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285 > Regex is short for Regular Expression. It helps to match, find or manage text. | Expression | Text | Description | Example | | ---------- | ------------------------------| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | | `.` | `abcABC123 .:!?` | A period signifies any character in the given position, including special characters and spaces. | Select everything: `abcABC123 .:!?` | | `[abc]` | `bar`, `ber`, `bir`, `bor`, `bur` | If one of the characters in a word can be various characters, we write it in square brackets `[]` with all alternative characters. | `b[aeiou]r` will find all the words. | | `^` | `bar` `ber` `bir` `bor` `bur` | To find all words in the text below, except for `ber` and `bor`, type `e` and `o` side by side after the caret `^` character inside square brackets `[]`. | `b[^eo]r` select only `bar`, `bir` and `bur` and not `ber` nor `bor` | | `[a-z]` | `abcdefghiklmnopqrstuvwxyz` | To find the letters in the specified range, the starting letter and the ending letter are written in square brackets `[]` with a dash between them `-`. | In `abcdefghiklmnopqrstuvwxyz`, `[e-o]` only selects `efghijklmno` | | `[0-9]` | `0123456789` | To find the numbers in the specified range | `[3-6]` select only `3456` in `0123456789` | | `*` | `br ber beer` | We put an asterisk `*` after a character to indicate that the character may either not match at all or can match many times. For example, indicate that the letter e should never occur in the text, or it can occur once or more side by side. | `be*r` | | `+` | `br ber beer` | To indicate that a character can occur one or more times, we put a plus sign `+` after a character. For example, indicate that the letter e can occur one or more times in the text. | `be+r` | | `?` | `color, colour` | To indicate that a character is optional, we put a `?` question mark after a character. For example, indicate that the following letter `u` is optional. | `colou?r` | | `{}` | `ber beer beeer beeeer` | To express a certain number of occurrences of a character, at the end we write curly braces `{n}` along with how many times we want it to occur. For example, indicate that the following letter e can occur only 2 times. | `be{2}r` | ## Regex for Response Validation [Set rules for your form - Google Docs Editors Help](https://support.google.com/docs/answer/3378864?hl=en#zippy=%2Cexamples-of-regular-expressions%2Ccheckboxes%2Cparagraph%2Cshort-answer) ## Ask for a specific format date (dd/mm/yyyy) `^([0-2][0-9]|(3)[0-1])(\/)(((0)[0-9])|((1)[0-2]))(\/)\d{4}
Voir [RegEx Testing](https://www.regextester.com/99555) pour obtenir un expression. chatGPT 3.5 donne cette réponse ``` ^(0[1-9]|1[0-9]|2[0-9]|3[01])/(0[1-9]|1[012])/(19|20)\d\d$ ``` > - `^`: Start of the string > - `(0[1-9]|1[0-9]|2[0-9]|3[01])`: Matches the day part of the date (01-31) > - `/`: Matches the slash character "/" > - `(0[1-9]|1[012])`: Matches the month part of the date (01-12) > - `/`: Matches the slash character "/" > - `(19|20)\d\d`: Matches the year part of the date (1900-2099) > - `
: End of the string Ceci marche également ``` ^\d{2}/\d{2}/\d{4}$ ``` # Demander une adresse se terminant en gmail.com ``` ^[a-zA-Z0-9_.+-]+@gmail\.com$ ``` > - `^`: Start of the string > - `[a-zA-Z0-9_.+-]+`: Matches one or more alphanumeric characters, underscore, dot, plus, or hyphen > - `@gmail\.com`: Matches the literal string "@gmail.com" > - `
: End of the string # Demander le site web d'un utilisateur ``` ^(https?:\/\/)?[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+[a-zA-Z]{2,6}(\/[a-zA-Z0-9_\/-]*)?$ ``` > - `^`: Start of the string > - `(https?:\/\/)?`: Matches an optional "http://" or "https://" at the beginning of the string > - `[a-zA-Z0-9_-]+`: Matches one or more alphanumeric characters, underscore, or hyphen (for the domain name) > - `(\.[a-zA-Z0-9_-]+)+`: Matches one or more occurrences of a dot followed by one or more alphanumeric characters, underscore, or hyphen (for subdomains or domain extensions) > - `[a-zA-Z]{2,6}`: Matches the top-level domain (TLD) with a length of 2 to 6 characters (e.g., com, org, co.uk) > - `(\/[a-zA-Z0-9_\/-]*)?`: Matches an optional forward slash followed by zero or more alphanumeric characters, underscore, hyphen, or forward slash (for paths or subdirectories) > - `
: End of the string > > Please note that this regex pattern is a general one and may not cover all possible variations of website addresses. --- # Google Form & Regex ## Partagé sur LinkedIn Regex, c'est super pratique. Vous pouvez, dans un formulaire, contraindre l'utilisateur à indiquer, par exemple, une date dans le format que vous souhaitez et pas un autre. Mais si, comme moi, vous n'y connaissez pas grand-chose, demandez à chatGPT d'écrire pour vous les expressions. En quoi cela peut-il concerner les enseignants ? Eh bien, vous pouvez poser une question de grammaire par exemple comme : Quelle est la classe grammaticale de « le train » ? On peut, grâce à Regex, répondre différentes choses. Par exemple, « C'est un déterminant suivi d'un nom » ou « groupe nominal » ou « C'est un groupe nominal.», etc. On a une souplesse que l'on n'a pas habituellement quand on pose ce type de question dont la réponse peut varier. Si la chose vous intéresse, faites le test avec ce formulaire. https://docs.google.com/forms/d/e/1FAIpQLSfWjR3EqSLjXg853uPQzrk4XArBQwd-rLMrLPy_mfNon3PFXQ/viewform ## Partagé sur Twitter Un peu de RegEx, un peu d'IA et vous pouvez poser à peu près n'importe quelle question à vos élèves dans des formulaires même si les réponses peuvent varier et être justes. Vos quiz vont prendre une tournure nouvelle ! Faites le test. https://docs.google.com/forms/d/e/1FAIpQLSfWjR3EqSLjXg853uPQzrk4XArBQwd-rLMrLPy_mfNon3PFXQ/viewform