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

时间:2016-06-01 20:07:25

标签: c# regex

我有以下字符串“*& abc = 123& **& defg = hh& *”等模式的开头和结尾是&& 我希望当我做regex.matches或regex.split

时有以下内容

第一场比赛= & abc = 123& 2匹配= & defg = hh&

感谢任何帮助

1 个答案:

答案 0 :(得分:1)

&[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
相关问题