Регулярное вырожение [Perl]

Discussion in 'PHP' started by FairHawk, 24 Jul 2010.

  1. FairHawk

    FairHawk Member

    Joined:
    16 Mar 2010
    Messages:
    46
    Likes Received:
    6
    Reputations:
    0
    Народ, есть строка:
    как из нее получить:
    в переменную $msg например
     
  2. haine

    haine New Member

    Joined:
    13 Dec 2009
    Messages:
    0
    Likes Received:
    0
    Reputations:
    0
    Приведи несколько примеров различных вариантов строки $data (чтобы знать от чего отталкиваться)
     
  3. novikov

    novikov New Member

    Joined:
    13 Apr 2010
    Messages:
    2
    Likes Received:
    0
    Reputations:
    0
    PHP:
    <?php 

    $data 
    ":[email protected] PRIVMSG #world :123";

    $msg preg_replace('/:([A-Z0-9_-]*)!.+(#[a-z0-9_-]*) :([0-9]*)$/''\\2 \\1 : \\3'$data);

    ?>
     
  4. FairHawk

    FairHawk Member

    Joined:
    16 Mar 2010
    Messages:
    46
    Likes Received:
    6
    Reputations:
    0
    novikov пустую строку выдает, да и preg_replace в perl нету вроде
     
  5. novikov

    novikov New Member

    Joined:
    13 Apr 2010
    Messages:
    2
    Likes Received:
    0
    Reputations:
    0
    Я думал регекспы везде одинаковые. В PHP работает.
     
  6. slashd

    slashd Elder - Старейшина

    Joined:
    3 Sep 2008
    Messages:
    56
    Likes Received:
    15
    Reputations:
    6
    Code:
    slashd@slashd-laptop:~/scripts$ cat src.pl 
    #!/usr/bin/perl
    
    use strict;
    
    my $data = ':[email protected] PRIVMSG #world :123';
    $data =~ m/^:(\w+?)!~.+?(#\w+?)\s:(\d+?)$/i;
    print $2," ",$1," : ",$3,"\n";
    slashd@slashd-laptop:~/scripts$ perl src.pl
    #world TEST11 : 123
    slashd@slashd-laptop:~/scripts$
    Но всё же остаётся вопрос со строкой "123", там всегда будут цифры?