【发布时间】:2013-08-14 17:17:16
【问题描述】:
我想关注一个包含 $foo AND $bar 的链接。
我试过了,但没有用。
$mech->follow_link( url_regex => qr/$foo/i && url_regex => qr/$bar/i)
【问题讨论】:
标签: perl hyperlink mechanize www-mechanize
我想关注一个包含 $foo AND $bar 的链接。
我试过了,但没有用。
$mech->follow_link( url_regex => qr/$foo/i && url_regex => qr/$bar/i)
【问题讨论】:
标签: perl hyperlink mechanize www-mechanize
您可以编写一个匹配两个子模式的正则表达式:
qr/(?=.*?$foo)(?=.*$bar)/is
由于.* 前缀,这使用了两个可以匹配字符串中任何位置的前瞻。
请注意,这样效率较低,匹配的子字符串会有所不同。
【讨论】:
$foo在字符串前面,$bar后面),你可以直接使用qr/$foo.*$bar/i,省力。
qr/$foo|bar/。