我基本上正在寻找一个匹配这些的正则表达式:
ProfileView
profile_views
views of candidate profile
viewed_profile
Run Code Online (Sandbox Code Playgroud)
但不是这些:
profile(profile)
view = candidate.view
Run Code Online (Sandbox Code Playgroud)
换句话说,我想要a.+b
或b.+a
不想a.+a
或b.+b
.
我认为这需要以某种方式捕获组,但我不太确定如何.(a|b).+(^\1)
......如果你理解我的意思,那就是这样的.
您需要使用交替运算符|
.
(?i)^(?:profile.*views?|views?.*profile)$
Run Code Online (Sandbox Code Playgroud)
s?
匹配一个可选的s
.(?i)
不区分大小写的修饰符,它有助于进行不区分大小写的匹配.