我需要正常表达的帮助,可以在下面执行;
08:30a所需输出8:30a
08:00p所需输出8p
02:45a所需输出2:45a
10:05a期望输出10:05a
12:53p期望输出12:53p
感谢您的帮助
答案 0 :(得分:0)
如果我了解你之后的事情 -
# Find: /(?:[0]([1-9])|([1][0-2]))(?:(?::00|(:[0][1-9]))|(:[1-5][0-9]))([aApP])[mM]?/
# Replace: $1$2$3$4$5
(?:
[0]
( [1-9] ) # (1)
|
( [1] [0-2] ) # (2)
)
(?:
(?:
: 00
|
( : [0] [1-9] ) # (3)
)
|
( : [1-5] [0-9] ) # (4)
)
( [aApP] ) # (5)
[mM]?
Perl测试用例
$/ = undef;
$str = <DATA>;
$str =~ s/(?:[0]([1-9])|([1][0-2]))(?:(?::00|(:[0][1-9]))|(:[1-5][0-9]))([aApP])[mM]?/$1$2$3$4$5/g;
print "$str\n";
__DATA__
08:30a desired output 8:30a
08:00p desired output 8p
02:45a desired output 2:45a
10:05a desired output 10:05a
12:53p desired output 12:53p
输出&gt;&gt;
8:30a desired output 8:30a
8p desired output 8p
2:45a desired output 2:45a
10:05a desired output 10:05a
12:53p desired output 12:53p