Need a regex to exclude certain strings

后端 未结 6 1424
无人及你
无人及你 2021-01-02 15:18

I\'m trying to get a regex that will match:

somefile_1.txt
somefile_2.txt
somefile_{anything}.txt

but not match:

somefile_1         


        
6条回答
  •  耶瑟儿~
    2021-01-02 15:35

    Sometimes it's just easier to use two regular expressions. First look for everything you want, then ignore everything you don't. I do this all the time on the command line where I pipe a regex that gets a superset into another regex that ignores stuff I don't want.

    If the goal is to get the job done rather than find the perfect regex, consider that approach. It's often much easier to write and understand than a regex that makes use of exotic features.

提交回复
热议问题