chad
September 26, 2018, 6:18am
1
For a very long time, I've had a question about regular expression repeaters. What is the difference between
[xyz+]
and
[xyz]+
?
(or between [xyz?] and [xyz]? - or of course same question using * )
Is one wrong and the other correct, or do they have their own valid meaning?
Florian
September 26, 2018, 6:33am
2
Both are correct regular expressions, but only the latter treats the + character as quantifier.
[xyz+] matches a single character present in the given list (including the + character).
[xyz]+ matches between one and unlimited occurrences of the characters present in the given list.
An other way to get a detailled explanation:
Enter your regex in one of the online regex tester like
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
There you can enter some text and see immediately how your regular expression would match (or not) a part of your text.
devfr
September 27, 2018, 1:57pm
4
Hi, you can visit this website to learn regular expression syntax : https://www.regular-expressions.info/quickstart.html
And visit this website to test regular expression: https://extendsclass.com/regex-tester.html