匹配url中的任何这些字符串

时间:2021-08-06 10:44:23

I'd like to use regex to determine if a url includes any of a number of strings (say "string1" OR "string2" )

我想使用正则表达式来确定一个url是否包含任何一个字符串(比如“string1”或“string2”)

I tried string1|string2. Not working. Ideas?

我试过string1 | string2。不工作。想法?

===========

Codespy's solution below works for the above. thx! However looking to modify my question a bit more. What if I want to do the following:

下面的Codespy解决方案适用于上述方案。谢谢!但是想要更多地修改我的问题。如果我想要执行以下操作该怎么办?

  1. match "abcd" OR "efgh" OR ( any url that includes BOTH "IJKL" AND ".MP3)
  2. 匹配“abcd”或“efgh”或(任何包含“IJKL”和“.MP3”的网址)

1 个解决方案

#1


1  

Try the following RegExp to solve your scenario.

尝试使用以下RegExp来解决您的方案。

//to match a stringX (X is any digit) pattern string
string[0-9]*

//to match any words 
[A-Za-z]*

//matches anything.mp3
([a-zA-Z0-9]+)(\.mp3)$

A Demo of RegExp using jQuery

使用jQuery演示RegExp

#1


1  

Try the following RegExp to solve your scenario.

尝试使用以下RegExp来解决您的方案。

//to match a stringX (X is any digit) pattern string
string[0-9]*

//to match any words 
[A-Za-z]*

//matches anything.mp3
([a-zA-Z0-9]+)(\.mp3)$

A Demo of RegExp using jQuery

使用jQuery演示RegExp