Repeater clarification


#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?


#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.


#3

An other way to get a detailled explanation:
Enter your regex in one of the online regex tester like

There you can enter some text and see immediately how your regular expression would match (or not) a part of your text.


#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