如何基于此URL进行不区分大小写的搜索

时间:2022-07-05 19:21:34

Here is the url i am trying to match

这是我想要匹配的网址

/anyfirsturl/apPles/1

the first part can be anything

第一部分可以是任何东西

/^\/[\w]*\/apples\i

This regular expression doesnt match anything so far

到目前为止,这个正则表达式无法匹配

I want it so the user can enter in APPLES or APPles or any way or for and any number after

我想要它,以便用户可以输入APPLES或APPles或任何方式或之后的任何数字

2 个解决方案

#1


2  

I think this should work:

我认为这应该有效:

/^\/[\w]*\/(apples)\/\d+$/i

the i option will do a case insensitive search, and should match all of those permutations.

i选项将执行不区分大小写的搜索,并且应匹配所有这些排列。

#2


1  

How about:

怎么样:

url =~ %r{^/.*/apples/\d+$}i

#1


2  

I think this should work:

我认为这应该有效:

/^\/[\w]*\/(apples)\/\d+$/i

the i option will do a case insensitive search, and should match all of those permutations.

i选项将执行不区分大小写的搜索,并且应匹配所有这些排列。

#2


1  

How about:

怎么样:

url =~ %r{^/.*/apples/\d+$}i