How to match, but not capture, part of a regex?

前端 未结 7 1593
清酒与你
清酒与你 2020-11-28 00:10

I have a list of strings. Some of them are of the form 123-...456. The variable portion \"...\" may be:

  • the string \"apple\" followed by a hyphen,
7条回答
  •  盖世英雄少女心
    2020-11-28 01:12

    Update: Thanks to Germán Rodríguez Herrera!

    In javascript try: /123-(apple(?=-)|banana(?=-)|(?!-))-?456/

    Remember that the result is in group 1

    Debuggex Demo

提交回复
热议问题