Hi, can you please help with regular expression for the following two cases?
1. I have to capture text in between (shown in single quotes)
' Name "USERSQL"
Value =+=+=+='
and
'=+=+=+='
Example, sample input:
Name "USERSQL" Value =+=+=+= text to be captured from here =+=+=+= do not capture this Name "USERSQL" Value =+=+=+= text sli to be captured wils from here aed =+=+=+= se do dex not capture wxq this
Name "USERSQL"
Value =+=+=+=
this should not be captured3
be either s
this is not correct match d
=+=+=+=
ksd lsidl
sd
The output should be
match1
text to be captured from here
match2
text sli to be captured wils from here aed
I used the following code but it includes the left and right 'boundaries' too,
and also matches match1 and not match2 ?
How to get both match1&2 and without including the start and end pattern?
string strInput = @" Name " + "\"USERSQL\"" + @"
Value =+=+=+=
text to
be captured
from here
=+=+=+=
do not
capture this
Name " + "\"USERSQL\"" + @"
Value =+=+=+=
text sli to
be captured wils
from here aed
=+=+=+=
se do dex not
capture wxq this" + @"
Name " + "\"USERSQL\"" + @"
Value =+=+=+=
this should not be captured3
be either s
this is not correct match d
=+=+=+=
ksd lsidl
sd";string patternstart = "^" + Regex.Escape(" Name \"USERSQL\"" + Environment.NewLine + " Value =+=+=+="); string patternend = Regex.Escape("=+=+=+="); string regexexpr = patternstart + @"(.*?)" + patternend; Regex regex = new Regex(regexexpr, RegexOptions.Singleline); MatchCollection matches = regex.Matches(strInput); foreach (Match m in matches) MessageBox.Show(m.Value);
2. From the content that appears in between '<SQL><SelectStatement' and '</SelectStatement></SQL>'
i have to capture only the text in between '[CDATA[' and ']]><'
<?xml abc def<SQL><SelectStatement gh ijkl'><![CDATA[text to be captured here for matches]]><mn op qur</SelectStatement></SQL>kkil mkhyg we ewd<SQL><SelectStatement wwe zfewf><![CDATA[text2 to be2 captured2 here for matches2]]>< wef zew dws</SelectStatement></SQL>sdf sdf
The output should be:
match1:
text to be captured here for matches
match2:
text2 to be2 captured2 here for matches2
Please ignore the extra blank lines added to the matches by this page code formatting
Thanks,
-srinivas y.