正则表达式,用于匹配模式与键值和字符串中的分隔符

时间:2022-09-13 12:20:18

trying to find the right regex to extract all of the values associated with the pos key in the below:

试图找到正确的正则表达式来提取下面与pos键相关的所有值:

"ip=78351;hmid=hi;hzcs=nl;lang=en;layer=nl;locale=en_us;nzcs=nl;ord=77053733
15;par=nl;plat=wx_droid_phone;plln=hi;pos=top300;rmid=1b97ef2c60b313a5e0c40"

would just extract: top300

只会提取:top300

1 个解决方案

#1


2  

Regex:

正则表达式:

\bpos=([^;]*)

Explanation:
It matches first the term pos=. And second matches everything until the next ; in a capturing group. This can be referenced later using $1 or \1 depending on the language you use.

说明:首先匹配术语pos =。第二个匹配所有东西,直到下一个;在捕获组中。稍后可以使用$ 1或\ 1来引用它,具体取决于您使用的语言。

DEMO

DEMO

#1


2  

Regex:

正则表达式:

\bpos=([^;]*)

Explanation:
It matches first the term pos=. And second matches everything until the next ; in a capturing group. This can be referenced later using $1 or \1 depending on the language you use.

说明:首先匹配术语pos =。第二个匹配所有东西,直到下一个;在捕获组中。稍后可以使用$ 1或\ 1来引用它,具体取决于您使用的语言。

DEMO

DEMO