我的源代码文件中有以下类型的文本:
html += T.m('current value of the quality level of the security service (as established from the diagnostic phase).');
or
{header: T.m("Service to Improve"), dataIndex : 'searvicesToImprove', hideable: false},
or
Ext.getCmp('MAX_ACTION_PLANS_PAGE').setText(T.m('od') + ' ' + MAX_ACTION_PLANS_PAGE);
我想提取括号内的子字符串,即。来自
T.m(X)
我想获得不带引号括号或带引号括号的 X
,然后我会修剪它们。
换句话说,我想要这样的东西:
regex( "T.m('X')" | "T.m("X")" );
and then say:
listOfMatches.add(X);
我知道这通常是用正则表达式完成的,但我对正则表达式不太擅长,没有太多使用它,仅用于基本示例。 非常感谢任何帮助。
var regex = new Regex(@"T\.m\((?<MyGroup>.*)\)");
var match =regex.Match(subject);
if(match.Success)
{
var found = match.Groups["MyGroup"].Value;
}
try {
Regex regexObj = new Regex(@"T\.m\([""|'](.+?)[""|']\)");
Match matchResults = regexObj.Match(subjectString);
while (matchResults.Success) {
var neededvalue = matchResults.Groups[1].Value;
}
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
如果您使用正则表达式并希望将所有部分分开,这可能会起作用
# @"(?s)T\.m\(((['""])((?:(?!\2).)*)\2)\)"
(?s) # dot all modifier
T \. m # 'T.m'
\( # Open parenth
( # (1 start), Quoted part
( ['"] ) # (2), Open Quote
( # (3 start), Body of quoted part
(?: # grouping
(?! \2 ) # lookahead, not a quote
. # any char
)* # end grouping, do 0 or more times
) # (3 end)
\2 # Close quote (group (2) backreference)
) # (1 end), Quoted part
\) # Close parenth
从小组中拿走你需要的东西