Answer the question
In order to leave comments, you need to log in
Help with regexp (Java)
There is some set of strings containing values separated by commas. Among them, you need to filter out those whose first value is either any number, or "NA".
Valid strings:
2,whatever
NA,whatever
45345,whatever
Invalid strings:
,whatever
bla-bla,whatever
a2,whatever
NANA,whatever
Okay, I wrote the expression:
(?m)^(\d+|NA{1}),.*
Everything works great. However, it later turned out that terminal characters (\t, \r, \n etc.) can occur in the whatever part. Modified the expression:
(?m)^(\d+|NA{1}),(.|\s)* (as an option - (?s)(?m)^(\d+|NA{1}),.* )
And it was not there, now all the lines, including invalid ones, began to satisfy him.
Tell me please, where did I go wrong?
Answer the question
In order to leave comments, you need to log in
(?<!\S)(?:NA|\d{1,}),(?:.|\s)+?(?=(?:\n.+,)|$)
Try this if you are feeding all lines at once and not one at a time. Well, the line separator was taken \n, if you mind that.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question