我想找出方括号内的整个字符串和一个单词。
示例字符串= [This is my first Question]
;
我要搜索[This ..
如果字符串包含[This
,我的预期输出应该是括号内的整个字符串。
有人可以使用正则表达式来帮助吗?任何帮助,将不胜感激。 我的代码如下:
string mainStr = 'wrapper s = [This is my first Question]';
Pattern pattr = Pattern.compile('\[This[^]]+\]');
Matcher mat = pattr .matcher(mainStr );
system.debug('mat is -----'+mat.matches());
system.debug('m is -----'+mat.find());
string n = null;
if(mat.matches()) { n = mat.group(); system.debug('m is ----'+n); }