0

I have this regex. It uses (?=.*(something)) to match unorded info. The matches I'm trying to find is M1, 1M, M5, 5M, M15, 15M. When you read the regex, focus on the middle. The left and right info is just to exemplify that I'm searching for another stuff too.

^(?=.*(\bsomething\b))(?=.*(\b[MmHh] ?(15?|1?5)|(1?5|15?) ?[MmHh]\b))(?=.*(\botherthing\b)).+

It works as expected when I remove the unorder feature. The problem happens is on 15M cenário. I think that maybe because it's not trying to find an left-right ordered info, 15M is never recognized.

When we have this scenario, it matches '5M' because it's found before. I read something about that the options inside a group (opt1|opt2|opt3) are read from left to right, so it should work when I put it separeteadely (15|5|1) instead of (1?5|15?). But it's not happening. M15 is working ok, bug 15M don't

How can I make this work? I just can't match it. I wish there's a way to set a priority on searching this. You can find a demo here:

https://regex101.com/r/yFvNi5/8

Leonardo Rick
  • 680
  • 1
  • 7
  • 14

0 Answers0