结合两个正则表达式 [英] Combine two regexes
问题描述
我有两个正则表达式,它们在独立使用时运行良好.
I have two regular expressions which are working perfectly fine when use independently.
First : ^.+\.((jpeg)|(gif)|(png))\s*$ : search for .jpeg,gif or png at the end of url
Second : ^.+(javax.faces.resource|rfRes).* : search for two url patterns
我想结合以上两个表达式,使得url以任何图像结尾"或url在其路径中有javax.faces.resource或rfRes"
I want to combine the above two expressions such that " url ends in any of the image " OR "url has javax.faces.resource or rfRes in its path"
我尝试使用 |操作员加入两者,但它似乎不像下面这样工作:
I tried using | operator to join both but it seems its not working like below :
^.+\.((jpeg)|(gif)|(png))\s*$ | ^.+(javax.faces.resource|rfRes).*
但它不起作用.
有人可以帮忙加入以上两个正则表达式吗?
Can anybody please help in joining above two regex ?
推荐答案
|
运算符周围有额外的空格:
You have extra spaces around the |
operator:
Your original regex
^.+\.((jpeg)|(gif)|(png))\s*$ | ^.+(javax.faces.resource|rfRes).*
^.+\.((jpeg)|(gif)|(png))\s*$|^.+(javax.faces.resource|rfRes).*
Fixed regex ^
|
您的解决方案将尝试匹配字符串的结尾然后是一个空格"或一个空格然后是字符串的开头".请记住,空格在正则表达式中很重要.
Your solution will try to match "the end of the string and then a space," or "a space and then the beginning of the string." Remember, whitespace is significant in regexes.
这篇关于结合两个正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!