-1

My question is similar to that in regex: Match at least two search terms, but with added complexity:

Given a set of M numerical strings of same length:

11001100
11101010
10010010
00101101

And given substring patterns of the type "11 at position 0" or "10 at position 6" (with the position being any multiple of 2), how can I search for strings matching at least N of these patterns?

For example: ^(11|\d{2}10|\d{6}10) matches all strings. However if I add {3,} to the regex to match "11101010" only (because it satisfies three out of three of those OR cases), it fails. Does anyone know how I can structure a regex like this?

If it matters, the patterns can also cover the same substring position, so for example it could be (11|\d{6}10|\d{6}00), and this ideally would match both the first and second lines in my example if I wanted to only catch strings with two or more matches.

Some Guy
  • 576
  • 1
  • 4
  • 17
  • This `^(11|\d{2}10|\d{6}10)` has a match in all 4 strings. – The fourth bird Dec 14 '21 at 13:54
  • Oops, sorry, fixed. – Some Guy Dec 14 '21 at 14:10
  • it might be easier to check if each line starts at 11 or ends at 10 than writing a regular expression – arutar Dec 14 '21 at 14:10
  • I guess my question wasn't clear enough, the position can be anywhere in the string. I'll edit it. – Some Guy Dec 14 '21 at 14:12
  • I think the question is not really clear. In the same string, `^11` can match only once. Matching 10 at position 6 can only be matched once, as there is only 1 position 6, and when matched the regex engine will go forward. You can use a quantifier `{3}` for example if there are enough characters in the string to match it like `^(11|\d{2}10|\d{6}10){3}` for string `11101000000010` – The fourth bird Dec 14 '21 at 14:13

1 Answers1

0

Is this the expected result?

(\b(11\d{6}|10\d{6}|\d{6}01)\n?){3,}
arutar
  • 1,015
  • 3
  • 9