I’m stuck with this regex
((["0"-"9"])+ ("-")*)*
(["0"-"9"])* ["a"-"z"] ( ["a"-"z","0"-"9"] )*
( ("-")+ (["a"-"z","0"-"9"])+)*
What I understand so far is:
((["0"-"9"])+ ("-")*)*
can be a number between 0-9. The plus means it can be repeated (e.g. 1157). Not sure about what the star does :S I think an example of this first line could be 1157- ?
(["0"-"9"])* ["a"-"z"] ( ["a"-"z","0"-"9"] )*
starts with a number, followed by a letters and numbers e.g. 1test5
( ("-")+ (["a"-"z","0"-"9"])+)*
optionally starts with a minus and follows by letters and numbers. e.g -54
If anyone could give me an example of a string that matches the regex it would be helpful. Finding is hard to understand this. 🙂
((["0"-"9"])+ ("-")*)*(["0"-"9"])*["a"-"z"]( ["a"-"z","0"-"9"] )*( ("-")+(["a"-"z","0"-"9"])+)*where:
To better understand this regex I have broken it into segments which are far easier to read. To get the total string just follow each segment and you will get strings that match this complete regex.
For segment 1:
1 or more digit followed by 0 to many hyphens ‘-‘, which can be repeated 0 or more times.
segment 2:
0 or many digits
segment 3:
only 1 lower case character (
"abcdefghijklmnopqrstuvwxyz")segment 4:
0 or many lower case characters or digits.
segment 5:
a hyphen 1 or more times followed by one or more lower case characters or digits, repeated 0 or more times.
By putting this together we can get the minimum string needed to fit this regex:
0a-awhere segments 2 and 4 can be ignored because they include 0 or more.
Some more examples will be:
to infinite length.