当前位置: 代码迷 >> HTML/CSS >> html正则表达式以及string含有参数
  详细解决方案

html正则表达式以及string含有参数

热度:97   发布时间:2012-08-21 13:00:21.0
html正则表达式以及string带有参数

1.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">?
<html xmlns="http://www.w3.org/1999/xhtml">?
<head>?
<body>?
?
<table cellpadding="2" cellspacing="0" border="0" width="100%" class="light_box">?
<tr>?
<td valign=top><b>Expiry Date:</b> 11 May 2010</td>?
?
<td align=right><b>Current Period:</b> Ends: 11 May 2010?
</td></tr>?
<tr>?
<td colspan=2>&nbsp;</td>?
</tr></table>?
</body>?
</html>?
String regexDate = "<b>Expiry Date:</b>(.+?)</td>";?
// ? ? ? ? ?String regexDate = "<b>Expiry Date:<\\/b>";?
? ? ? ? ? ?
Pattern p = Pattern.compile(regexDate);?
? ? ? ? ? ?
String[] items = p.split(returnedHTML);?
? ? ? ? ? ?
System.out.println("*******REGEX 1 RESULT*******"); // prints whatever the .+? expression matched.?
? ? ? ? ? ?
for(String s : items) ?
? ? ? ? ? ?
{ ?
? ? ? ? ? ? ? ?
System.out.println(s); ?
? ? ? ? ? ?
}?
? ? ? ? ? ?
System.out.println("*******REGEX 1 RESULT*******"); // prints whatever the .+? expression matched.?
?
? ? ? ? ? ?
Pattern p2 = Pattern.compile("<b>Expiry Date:<\\/b>");?
? ? ? ? ? ?
Matcher m = p2.matcher(returnedHTML);?
?
? ? ? ? ? ?
if (m.matches()) // check if it matches (and "generate the groups")?
? ? ? ? ? ?
{?
? ? ? ? ? ? ? ?
System.out.println("*******REGEX 2 RESULT*******"); // prints whatever the .+? expression matched.?
? ? ? ? ? ? ? ?
System.out.println(m.group(1)); // prints whatever the .+? expression matched.?
? ? ? ? ? ? ? ?
System.out.println("*******REGEX 2 RESULT*******"); // prints whatever the .+? expression matched.?
? ? ? ? ? ?
}?

?

?

String regexDate = "<b>Expiry Date:</b>(.+?)</td>";?
Pattern p = Pattern.compile(regexDate);?
Matcher m = p.matcher(returnedHTML);?
?
if (m.matches()) // check if it matches (and "generate the groups")?
{?
?
System.out.println("*******REGEX RESULT*******"); ?
?
System.out.println(m.group(1)); // prints whatever the .+? expression matched.?
?
System.out.println("*******REGEX RESULT*******"); ?
}?


2.

<string name="string_one">My string</string>?
<string name="string_two">Here it is: %s" </string>?

?

String.format(getString(R.string.string_two), getString(R.string.string_one));?
  相关解决方案