Regex: How to capture optional group in middle of text?

前端 未结 2 629
忘了有多久
忘了有多久 2021-01-25 14:18

I\'m struggling with using regex to capture some optional text - it\'s in the middle of some filenames, but not all. The big problem appears to be that my optional group is not

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-25 14:51

    I'm not particularly familiar with the format you are trying to use, but I believe I came up with an example of something that tackles the problem you have.

    http://regexr.com/3cs8g

    /name ((\([0-9]+\))|([0-9]+)) ((color shape)|(shape( color)?))( version)?/ig
    

    What your describing is an optional clause that can appear in one of two spots. So, you make an or statement to test for each possible spot.

提交回复
热议问题