Regular Expressions: Is there an AND operator?

后端 未结 12 2213
刺人心
刺人心 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:19

    Look at this example:

    We have 2 regexps A and B and we want to match both of them, so in pseudo-code it looks like this:

    pattern = "/A AND B/"
    

    It can be written without using the AND operator like this:

    pattern = "/NOT (NOT A OR NOT B)/"
    

    in PCRE:

    "/(^(^A|^B))/"
    
    regexp_match(pattern,data)
    

提交回复
热议问题