Regular expression with an = and a ;

狂风中的少年 提交于 2019-12-03 23:25:55

This may be what you are looking for. You need to specify a character set or wild card character that you are applying the asterisk to.

"=([^;]*);"

You can also use the reluctant quantifier:

"=(.*?);"

Using the parenthesis you now have groups. I believe the first group is the whole entire match, and group[1] is the group found within the parenthesis.

The code may look something like:

Regex r = new Regex("=([^;]*);");
Match m = r.Match(yourData);
while (m.Success) {
    string match = m.Groups[1];
    // match should be the text between the '=' and the ';'.
}

This looks for "any number of = signs, including 0"

=*;

If you want "= followed by any number of other characters" you want

=.*;

However, that will match greedily - if you want lazy matching (so that it stops one group when it finds the next semicolon) you might want:

=.*?;

The regex you provided would match ;, ===;, ..., ================;. How about =.*; (or =.*?; if non-greedy is needed)?

An excellent source for learning about regexp in Java: sun's book about regexp

Something like =.*;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!