I am a beginner at Perl and have a section of data like the following:
我是Perl的初学者,有一段如下数据:
ATOM 2067 N SER 7 316 -2.78500 -0.14800 -0.01300 N_R 3 0 -0.47000 0 0
ATOM 2068 HN SER 7 316 -2.51586 0.06218 0.89490 H___A 1 0 0.31000 0 0
ATOM 2069 CA SER 7 316 -3.57800 -1.36200 -0.28500 C_3 4 0 0.07000 0 0
I want to be able to print to another file lines of the data without H_ in each line. Could you help me identify the error in my regular expression.
我希望能够在每行中没有H_的情况下打印到数据的另一个文件行。你能帮我识别正则表达式中的错误吗?
while (<localBGF>)
{
$line = $_;
if ($line =~ /^ATOM\s+\d+\s+(\S+)\s+SER/)
{
if ($line !~ /^ATOM\s+\d+\s+(\S+)\s+SER\s+\d\s+\d\s+\d\s+\d\s+\d\s+H_/)
{
print BGF $line;
}
}
}
1 个解决方案
#1
1
Since you've already identified with the first regex that the line matches ^ATOM\s+\d+\s+(\S+)\s+SER
for the second you can just check that $line !~ /.*H_.*/
因为你已经用第一个正则表达式识别出该行匹配^ ATOM \ s + \ d + \ s +(\ S +)\ s + SER,你可以检查$ line!〜/。* H_.*/
#1
1
Since you've already identified with the first regex that the line matches ^ATOM\s+\d+\s+(\S+)\s+SER
for the second you can just check that $line !~ /.*H_.*/
因为你已经用第一个正则表达式识别出该行匹配^ ATOM \ s + \ d + \ s +(\ S +)\ s + SER,你可以检查$ line!〜/。* H_.*/