简体   繁体   English

正则表达式可能包含一个字符

[英]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

RegEx Demo RegEx演示

([^;]*) 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.

相关问题 正则表达式用于分隔值的列表,其中值可能包含分隔符 - regex for a list of separated values where values may contain the separator character 正则表达式匹配可能包含标点符号的单词的边界 - Regex matching the boundary of a word that may contain punctuation 正则表达式字符集-以及它们包含的内容 - Regex character sets - and what they contain 当URL可能包含或不包含HTTP和WWW时,URL的JavaScript正则表达式 - JavaScript Regex for URL when the URL may or may not contain HTTP and WWW Intellij IDEA正则表达式字符类不能在字符范围内使用 - Intellij IDEA regex character class may not be used inside character range RegEx:匹配不包含[字符的字符串行] - RegEx : Match line of string that does not contain [ character 正则表达式“必须包含此范围之外的字符”? - Regex for "must contain a character outside of this range"? 正则表达式至少包含 1 个特殊字符但不包含特定字符 - Regex to contain at least 1 special character but not specific characters 正则表达式,用于删除指定集中包含* not *字符的单词 - RegEx for removing words that contain a character *not* in a specified set RegEx:从可能包含多个“ {”和“}”的字符串中提取子字符串 - RegEx: Extract substring from a string which may contain several number of '{' and '}'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM