Regular expressions: Ensuring b doesn't come between a and c

前端 未结 4 1187
无人共我
无人共我 2020-11-22 15:26

Here\'s something I\'m trying to do with regular expressions, and I can\'t figure out how. I have a big file, and strings abc, 123 and xyz

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 16:06

    Using PCRE a solution would be:

    This using m flag. If you want to check only from start and end of a line add ^ and $ at beginning and end respectively

    abc(?!.*(abc|xyz).*123).*123(?!.*(abc|xyz).*xyz).*xyz
    

    Regular expression visualization

    Debuggex Demo

提交回复
热议问题