admin管理员组文章数量:1402050
I have 2 kinds of data.
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
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.
I have 2 kinds of data.
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
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.
Share Improve this question asked Jul 25, 2015 at 11:11 user2565496user2565496 251 gold badge1 silver badge6 bronze badges2 Answers
Reset to default 2You can use:
/\bws=([^;]*)/
and grab captured group #1
RegEx Demo
([^;]*)
will match 0 or more of any character that is not ;
I would use this:
ws=(.*?)(;|$)
Try it online: http://regexr./3bfbv
ws=
searches for that exact text(
starts the matching group.*?
searches for any characters, but as few characters as possbile ("non-greedy"))
stops the matching group(;|$)
searches for either a;
or the end of the text (or the line)
本文标签: javascriptRegex may contain a characterStack Overflow
版权声明:本文标题:javascript - Regex may contain a character - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744344025a2601649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论