I am attempting to create a regex that will match all uppercase letters before the first question mark in a URL string:
我正在尝试创建一个regex,它将匹配URL字符串中的第一个问号之前的所有大写字母:
/foO/baR/?_heLLo=1320957051041105000&_woRld=0
/ foO / baR / ? _heLLo = 1320957051041105000 &_world = 0
I have tried both the following:
我尝试过以下两种方法:
(?<!(\?))([A-Z])
(?<!\?.*?)([A-Z])
(? < !(\))([a - z])(? < ! \ ?。* ?)([a - z])
The former captures uppercase letters before and after the question mark. The latter captures no uppercase letters. Any insight would be appreciated, thanks.
前者在问号之前和之后捕获大写字母。后者没有捕获大写字母。如有任何见解,我们将不胜感激,谢谢。
2 个解决方案
#1
1
Try this positive lookbehind:
试试这个积极的向后插入:
(?<=^[^?]*)[A-Z]
#2
2
This regex would do the trick:
这个regex将完成以下操作:
[A-Z](?=.*?\?)
See it in action here: http://regexr.com?2v5r0
请参见这里的操作:http://regexr.com?2v5r0。
#1
1
Try this positive lookbehind:
试试这个积极的向后插入:
(?<=^[^?]*)[A-Z]
#2
2
This regex would do the trick:
这个regex将完成以下操作:
[A-Z](?=.*?\?)
See it in action here: http://regexr.com?2v5r0
请参见这里的操作:http://regexr.com?2v5r0。