RegEx匹配URL的结尾

时间:2021-04-24 10:35:07

I'd like to match strings ending with /web/ or /mobile/

我想匹配以/ web /或/ mobile /结尾的字符串

I wrote this RegEx:

我写了这个RegEx:

(/web/|/mobile/)$

(/网络/ | /移动/)$

but it's not working as expected, I tested with https://regex101.com/r/P2p4sa/1/

但它没有按预期工作,我测试了https://regex101.com/r/P2p4sa/1/

What am I missing? Are there any more clever expressions I could use?

我错过了什么?有没有更聪明的表达我可以使用?

1 个解决方案

#1


1  

The problem is that $ only matches the end of the whole input by default. Just enable "Multiline" in the flag options (right side of the regex input). This will let $ match the end of each line.

问题是$默认只匹配整个输入的结尾。只需在标志选项中启用“Multiline”(正则表达式输入的右侧)。这将让$匹配每一行的结尾。

When you use it in your code, setting the flag is only necessary if your input consists of multiple lines.

在代码中使用它时,只有在输入包含多行时才需要设置标志。

#1


1  

The problem is that $ only matches the end of the whole input by default. Just enable "Multiline" in the flag options (right side of the regex input). This will let $ match the end of each line.

问题是$默认只匹配整个输入的结尾。只需在标志选项中启用“Multiline”(正则表达式输入的右侧)。这将让$匹配每一行的结尾。

When you use it in your code, setting the flag is only necessary if your input consists of multiple lines.

在代码中使用它时,只有在输入包含多行时才需要设置标志。