English 中文(简体)
Concatenate regex s + ...... perl
原标题:Concatenate regex s+ w+ ... perl
  • 时间:2012-05-09 09:19:01
  •  标签:
  • regex
  • perl

我有这样的条目:

    XYZABC------------HGTEZCW
    ZERTAE------------RCBCVQE

I would like to get just HGTEZCW and RCBCVQE . I would like to use a generic regex.

$temp=~ s/^s+//g;     (1)
$temp=~ s/^w+[-]+//g; (2)

If i use (1) + (2) , it works. It works i get : HGTEZCW, then RCBCVQE ...

我想知道,在以下一行中,是否有可能做到这一点:

$temp=~ s/^s+w+[-]+//g; (3)

当我使用第(3)条时,即取得这一结果: HGTEZ : / 准则

我无意理解为什么不可能将1+2混为一谈。

我的条目是:

    XYZABC------------HGTEZCW
    ZERTAE------------RCBCVQE

Also, the regex 1 remove space but when i use regex2, it remove XYZABC------------ . But the combination (3), don t work. i have this XYZABC------------HGTEZCW

@Tim So there always is whitespace at the start of each string? yes

最佳回答

页: 1 因此,这在你的例子中没有任何意义。

登记号(2)从插头开始除去所有字母数字,然后回到最后的干线。

如果将两者结合起来,则由于没有白天空间<条码>+而未能做到——因此整个舱位都失败。

为了解决这一问题,简单地使白天成为选择。 也无需在括号中附上<代码>-:

$temp=~ s/^s*w+-+//g;
问题回答

这应当做到。

$Str =  
    XYZABC------------HGTEZCW
    ZERTAE------------RCBCVQE
 ;

@Matches = ($Str =~ m#^.+-(w+)$#mg);

print join "
",@Matches ;

如果你只需要每个条目的最后七个特点,你可以做如下工作:

$temp =~ /.{7}$/;




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签