Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
'***********************************************************
' マッチした文字列の表示
'***********************************************************
regEx.Pattern = "[""']*http://" & "[^>""'\s]+" & "[""']*"
strText = _
"<A href=http://abcd.com/index.htm>" & vbCrLf & _
"<A href=""http://abcd.com/index.htm"">" & vbCrLf & _
"<A href='http://abcd.com/index.htm'>" & vbCrLf & _
"<A href=http://abcd.com/index.htm style='color:black'>"
Set Matches = regEx.Execute( strText ) ' 検索
For Each Match in Matches
WScript.echo Match.Value
Next
WScript.echo
'***********************************************************
' サブマッチした文字列の表示
'***********************************************************
regEx.Pattern = "([""']*)(http://" & "[^>""'\s]+)" & "([""']*)"
strText = _
"<A href=http://abcd.com/index.htm>" & vbCrLf & _
"<A href=""http://abcd.com/index.htm"">" & vbCrLf & _
"<A href='http://abcd.com/index.htm'>" & vbCrLf & _
"<A href=http://abcd.com/index.htm style='color:black'>"
Set Matches = regEx.Execute( strText ) ' 検索
For Each Match in Matches
WScript.echo "1) " & Match.SubMatches(0)
WScript.echo "2) " & Match.SubMatches(1)
WScript.echo "3) " & Match.SubMatches(2)
WScript.echo
Next
$text =
"<A href=http://abcd.com/index.htm>\n" .
"<A href=\"http://abcd.com/index.htm\">\n" .
"<A href='http://abcd.com/index.htm'>\n" .
"<A href=http://abcd.com/index.htm style='color:black'>\n";
while ( $text =~ /["']*http:\/\/[^>"'\s]+["']*/i ) {
print $& . "\n";
$text = $';
}
print "\n";
$text =
"<A href=http://abcd.com/index.htm>\n" .
"<A href=\"http://abcd.com/index.htm\">\n" .
"<A href='http://abcd.com/index.htm'>\n" .
"<A href=http://abcd.com/index.htm style='color:black'>\n";
while ( $text =~ /(["']*)(http:\/\/[^>"'\s]+)(["']*)/i ) {
print "1) $1 \n";
print "2) $2 \n";
print "3) $3 \n";
print "\n";
$text = $';
}
<?
$text =
"<A href=http://abcd.com/index.htm>\n" .
"<A href=\"http://abcd.com/index.htm\">\n" .
"<A href='http://abcd.com/index.htm'>\n" .
"<A href=http://abcd.com/index.htm style='color:black'>\n";
preg_match_all( '/["\']*http:\/\/[^>"\'\s]+["\']*/i', $text, $match, PREG_PATTERN_ORDER );
for( $i = 0; $i < count( $match[0] ); $i++ ) {
print $match[0][$i] . "\n";
}
print "\n";
$text =
"<A href=http://abcd.com/index.htm>\n" .
"<A href=\"http://abcd.com/index.htm\">\n" .
"<A href='http://abcd.com/index.htm'>\n" .
"<A href=http://abcd.com/index.htm style='color:black'>\n";
preg_match_all( '/(["\']*)(http:\/\/[^>"\'\s]+)(["\']*)/i', $text, $match, PREG_PATTERN_ORDER );
for( $i = 0; $i < count( $match[0] ); $i++ ) {
print "1) {$match[1][$i]}\n";
print "2) {$match[2][$i]}\n";
print "3) {$match[3][$i]}\n";
print "\n";
}
?>