正则表达式:是否有AND运算符? [英] Regular Expressions: Is there an AND operator?

查看:123
本文介绍了正则表达式:是否有AND运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很明显,您可以使用|(竖线?)来表示OR,但是也可以使用一种方式来表示AND吗?

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

具体来说,我想匹配包含某个短语的全部但没有特定顺序的文本段落.

Specifically, I'd like to match paragraphs of text that contain ALL of a certain phrase, but in no particular order.

推荐答案

使用非消耗性的正则表达式.

Use a non-consuming regular expression.

典型的(即Perl/Java)表示法是:

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

(?= expr )

这意味着匹配 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.

这篇关于正则表达式:是否有AND运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆