regex 正则表达式匹配字符串中的模式多次

hvvq6cgz  于 2023-06-30  发布在  其他
关注(0)|答案(1)|浏览(113)

我有下面的字符串“&abc=123&**&defg=hh&”等等,模式的开始和结束是 &&,我希望在执行regex.matches或regex.split时有以下内容
第一个匹配= &abc=123& 2匹配= &defg=hh&
感谢任何帮助

xxslljrj

xxslljrj1#

&[0-9a-zA-Z]+=[0-9a-zA-Z]+&

您可能需要更改[0-9a-zA-Z],具体取决于您希望允许的字符。

& matches the characters & literally
[0-9a-zA-Z]+ match a single character present in the list below
    Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
    0-9 a single character in the range between 0 and 9
    a-z a single character in the range between a and z (case sensitive)
    A-Z a single character in the range between A and Z (case sensitive)
= matches the character = literally
[0-9a-zA-Z]+ match a single character present in the list below
    Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
    0-9 a single character in the range between 0 and 9
    a-z a single character in the range between a and z (case sensitive)
    A-Z a single character in the range between A and Z (case sensitive)
& matches the characters & literally

相关问题