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

前端 未结 7 1538
清酒与你
清酒与你 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

    0 讨论(0)
提交回复
热议问题