?
. Esto comprueba si hay cero o uno de los elementos anteriores. Puede pensar que este símbolo dice que el elemento anterior es opcional.
Por ejemplo, hay ligeras diferencias entre el inglés americano y el británico y puede usar el signo de interrogación para hacer coincidir ambas ortografías.
let american = "color";
let british = "colour";
let rainbowRegex= /colou?r/;
rainbowRegex.test(american); // Returns true
rainbowRegex.test(british); // Returns true
favRegex
para que coincida con la versión del inglés americano (favorito) y del inglés británico (favorito) de la palabra.
?
.
testString: 'assert(favRegex.source.match(/\?/).length > 0, "Your regex should use the optional symbol, ?
.");'
- text: Tu expresión regular debe coincidir con "favorite"
testString: 'assert(favRegex.test("favorite"), "Your regex should match "favorite"
");'
- text: Tu expresión regular debe coincidir con "favourite"
testString: 'assert(favRegex.test("favourite"), "Your regex should match "favourite"
");'
- text: Tu expresión regular no debe coincidir con "fav"
testString: 'assert(!favRegex.test("fav"), "Your regex should not match "fav"
");'
```