The regex I currently have is:
"^(?:(\\.\\.)|^([a-z]+[a-z.\\-]*)([\\*]?)[\\[]*([^\\]]*)[\\]]*)$";
It captures either “..” (group 1) with group 2-4 being empty
or:
– a group of lowercase, dots, dashes. starting with lowercase (group 2)
– followed by optional asterisk (group 3)
– followed by optional content within square brackets (group 4)
I’m having a couple problems, first is making it so group2 must end with a letter, I have tried many things including:
"^([a-z]+[a-z.\\-]*[a-z]$)"
"^([a-z]+[a-z.\\-]*[a-z])$"
which kills anything in group 3-4
"^([a-z]+[a-z.\\-]*[a-z])"
which doesn’t seem to do anything different
The other problem I’m having is group 4, it doesn’t depend on the square brackets (which makes sense as I have the * character for them)… but if I remove that character it will not give me any results for ANY of the groups.
Any help is greatly needed and appreciated.
In response to comment below, the following should match:"string" - (group1)(group2)(group3)(group4)
".." - (..)()()()
"blah" - ()(blah)()()
"blah.blah" - ()(blah.blah)()()
"blah.blah*" - ()(blah.blah)(*)()
"blah*" - ()(blah)(*)()
"blah.blah*[foobar] - ()(blah.blah)(*)(foobar)
"blah[foobar] - ()(blah)()(foobar)
The following should not match:
"."
"..."
".blah"
"blah."
".blah*"
"blah.*[foobar]
1 Answer