简体   繁体   English

如何写正则表达式以特定的字符串开始和结束?

[英]how to write regex starts and ends with particular string?

How to write regex for this paricular situation. 如何为这种特殊情况编写正则表达式。 Here letters in [] is not fixed but letters without [] is fixed. 这里[]中的字母不是固定的,但是没有[]的字母是固定的。

http://www.abc.com/fixed/[any small letters]/[anyletters]/fixed.html
http://www.abc.com/fixed/[a-z]+/[a-zA-Z]+/fixed.html

可能更改为更宽容:

http://www.abc.com/fixed/[a-z]+/[^/]+/fixed.html

You can use lookarounds for that. 您可以为此使用环顾四周 One problem may be that they are not available in every language. 一个问题可能是并非每种语言都提供它们。 For instance Javascript has only positive lookahead. 例如,JavaScript仅具有积极的前瞻性。

Oh, you mean something different... try this: 哦,您的意思有所不同...试试这个:

http://www.abc.com/fixed/[a-z]+/[\w\D^_]+/fixed.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM