a和a的正则表达式 [英] Regular expression with an = and a ;

查看:134
本文介绍了a和a的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用正则表达式来查找以等号( = )开始的所有子字符串,并以分号结尾( ; ),其间包含任意数量的字符。它应该是这样的东西 = *;

I'm trying to use a regular expression to find all substrings that start with an equals sign (=) and ends with a semicolon (;) with any number of characters in between. It should be something like this =*;

由于某些原因,equals不会注册。有没有某种转义字符会使正则表达式通知我的等号?

For some reason, the equals is not registering. Is there some sort of escape character that will make the regex notice my equals sign?

如果对这个问题有任何影响,我正在Java工作。 >

I'm working in Java if that has any bearings on this question.

推荐答案

这可能是您正在寻找的。您需要指定要应用星号的字符集或通配符。

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:

"=(.*?);"

使用您现在拥有组的圆括号。我相信第一组是整个比赛,而 group [1] 是在括号内找到的组。

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.

代码可能看起来像:

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 ';'.
}

这篇关于a和a的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆