See the following HTML example.Code
< Div >
< IMG ALT ='' SRC = "/Upload/image/111.jpg" /> < IMG ALT ='' SRC = '/Upload/image/222.jpg' /> < IMG
SRC = './Upload/image/333.jpg' ALT ='' /> </ Div >
< Div >
< IMG ALT ='' SRC = '/Upload/image/444.jpg' />
< IMG SRC = '../SA/upload/image/333.jpg' ALT ='' />
</ Div >
Now we need to retrieve the SRC from IMG. The regular expression is as follows:
< IMG [ ^> ] * SRC \ s * = \ S * [ ' "] ([\ W/\-\.] *) [ '" ] [^>] *
Explanation:
<IMG [^>]*: Search for the content starting with .
SRC \ s* =\ S*['"] ([\ W/\-\.] *) ['"] [^>] *: Search for the content starting with SRC, ending with>, and taking the content in SRC.
\ S *: 0 or multiple Spaces
['"]:Take a 'or'.
([\ W/\-\.] *):Take the word character, including _/-. And other characters. (), Indicating to useGroupsMethod to obtain the value.
Usage:
Private Void Findimageinxmlmethod ()
{
String Imgxml = " <Div> " / Upload / Image / 111 . Jpg \ " /> </div> "
+ @" <Div>
</Div> " ;
String RegEx = " ] * SRC \ s * = \ s *['\ " ] ([\ W / \\ - \.] * )[ ' \ "] [^>] *";
RegEx imgregex = New RegEx (RegEx, regexoptions. ignorecase );
Matchcollection = Imgregex. Matches (imgxml );
Foreach (Match matchitem In Matchcollection)
{
String Val = Matchitem. value;
Val = Matchitem. Groups [ 1 ]. Value;
Response. Write (Val + " <Br/> " );
}
}
Result:
/ Upload / Image / 111 . Jpg
/ Upload / Image / 222 . Jpg
. / Upload / Image / 333 . Jpg
/ Upload / Image / 444 . Jpg
.. / SA / Upload / Image / 333 . Jpg