[英]Regex may contain a character
I have 2 kinds of data. 我有2种数据。
One data is something like this 一个数据是这样的
ws=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9
and the another data like this 和另一个这样的数据
ws=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9;utmz=111872281.1437151704.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
I wanna get the ws value, like 我想获得ws值,比如
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9
But i got problems for split the ";" 但是因为分裂“我”而遇到了问题。 character.
字符。 Because sometime the data have the character, but sometimes it doesn't have that character.
因为有时数据具有该字符,但有时它没有该字符。
I already tried using 我已经尝试过了
ws=([^]*);?
and 和
ws=([^]*)[;?]
and I still doesn't get the correct data. 我仍然没有得到正确的数据。 Thank you very much.
非常感谢你。
You can use: 您可以使用:
/\bws=([^;]*)/
and grab captured group #1 并抓住被捕获的组#1
([^;]*)
will match 0 or more of any character that is not ;
([^;]*)
将匹配0或更多任何不符合的字符;
I would use this: 我会用这个:
ws=(.*?)(;|$)
Try it online: http://regexr.com/3bfbv 在线试用: http : //regexr.com/3bfbv
ws=
searches for that exact text ws=
搜索该确切文本 (
starts the matching group (
启动匹配组 .*?
searches for any characters, but as few characters as possbile ("non-greedy") )
stops the matching group )
停止匹配组 (;|$)
searches for either a ;
(;|$)
搜索a ;
or the end of the text (or the line)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.