I am trying to write a Java regex that will find all lines between 2 :. If a line between characters has spaces, line ends, or tabs, it should be ignored. Blank lines are also ignored. _OK! A group may include either included :or not.
Here are some tests and expected groups:
"test :candidate: test" => ":candidate:"
"test :candidate: test:" => ":candidate:"
"test :candidate:_test:" => ":candidate:", ":_test:"
"test :candidate::test" => ":candidate:"
"test ::candidate: test" => ":candidate:"
"test :candidate_: :candidate: test" => ":candidate_:", ":candidate:"
"test :candidate_:candidate: test" => ":candidate_:", ":candidate:"
I tested a lot of regular expressions and they almost work:
":(\\w+):"
":[^:]+:"
I still have a problem when two groups "divide" the colon:
"test :candidate_: :candidate: test" => ":candidate_:", ":candidate:"
"test :candidate_:candidate: test" => ":candidate_:"
It seems that the first group “consumes” the second colon and that the matches cannot find the second line that I expected.
- , ?
, "" ?
.