...以下元字符具有[特殊]含义:
\ Quote the next metacharacter
^ Match the beginning of the line
. Match any character (except newline)
$ Match the end of the string (or before newline at the end
of the string)
| Alternation
() Grouping
[] Bracketed Character class
http://perldoc.perl.org/perlre.html
括号字符类中的特殊字符
大多数字符
是正则表达式中的元字符(即字符
带有特殊含义(如 .、* 或 () 的)失去其特殊意义
含义并且可以在字符类中使用而无需
逃离他们。例如,[()] 匹配左括号,
或右括号,以及字符类中的括号
不要分组或捕获。
在字符类中可能带有特殊含义的字符
是:\、^、-、[ 和 ],并在下面讨论。他们可以逃脱
带反斜杠,虽然有时不需要,在这种情况下
反斜杠可以省略。
http://perldoc.perl.org/perlrecharclass.html#Bracketed-Character-Classes
use strict;
use warnings;
use 5.016;
my @lines;
my $regex = qr{
.*? #Match any character, 0 or more times, non-greedy, followed by...
-{3} #a dash, 3 times, followed by...
\$ #a dollar sign, followed by...
[ ] #a space, followed by...
(.*) #any character, 0 or more times, captured in $1
}xms;
for my $line (<DATA>) {
if ($line =~ $regex) {
push @lines, $1;
}
}
print for @lines;
__DATA__
(8092) "DEFECT_AUDIT_INTTEST_FRI_JAN_02_2015_07_05_09" (3 of 4)
(7992) ---$ FirstName1 Surname1 "Comment number 1" 02-Jan-2015 01:53 AM
(8007) ---$ FirstName2 Surname2 "Comment number 2" 19-Dec-2014 06:20 AM
(7994) ---$ FirstName3 Surname3 "Comment number 3" 19-Dec-2014 06:46 AM
输出:
FirstName1 Surname1 "Comment number 1" 02-Jan-2015 01:53 AM
FirstName2 Surname2 "Comment number 2" 19-Dec-2014 06:20 AM
FirstName3 Surname3 "Comment number 3" 19-Dec-2014 06:46 AM
正则表达式中的大多数元字符(即带有特殊含义的字符,如 .、* 或 () 失去了它们的特殊含义,并且可以在字符类中使用而无需对其进行转义。对于例如,[()] 匹配左括号或右括号,并且字符类中的括号不会分组或捕获。
在字符类中可能带有特殊含义的字符有:\、^、-、[ 和],这些将在下面讨论。它们可以用反斜杠转义,尽管有时不需要,在这种情况下可以省略反斜杠。
http://perldoc.perl.org/perlrecharclass.html#Bracketed-Character-Classes
关于 $??!