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

前端 未结 2 608
忘了有多久
忘了有多久 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:41

    Try putting the .*?(foo) parts in parentheses like (.*?(foo)) so that the ? operator will take the .*? parts into consideration.

    Corrected syntax (.*?).\(?(\d{4})(.*?(color))?.*?(shape)(.*?(color))?(.*?(version))?.* (example)

提交回复
热议问题