if we use the parentheses in the RE, it will store the matched string to the memory. the first parentheses' string stored to $1 the second to $2 and so on. if we don't use the matched string, we can use ?: to ignore the matched one.
- if (/(?:bronto)?saurus (steak|burger)/) {
-
print "Fred wants a $1\n";
-
}
even if we add something to the RE, it will not change the group number
- if (/(?:bronto)?saurus (?:BBQ )?(steak|burger)/) {
-
print "Fred wants a $1\n";
-
}
阅读(403) | 评论(0) | 转发(0) |