Regular Expressions: Is there an AND operator?

后端 未结 12 2007
刺人心
刺人心 2020-11-21 06:34

Obviously, you can use the | (pipe?) to represent OR, but is there a way to represent AND as well?

Specifically, I\'d like to

12条回答
  •  野性不改
    2020-11-21 07:22

    Use a non-consuming regular expression.

    The typical (i.e. Perl/Java) notation is:

    (?=expr)

    This means "match expr but after that continue matching at the original match-point."

    You can do as many of these as you want, and this will be an "and." Example:

    (?=match this expression)(?=match this too)(?=oh, and this)

    You can even add capture groups inside the non-consuming expressions if you need to save some of the data therein.

提交回复
热议问题