Regax Prob

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lokeshrajoria
    New Member
    • Jun 2007
    • 35

    Regax Prob

    Hello Everyone,
    here i am posting regex prob. can anybody tell me why is not working. i want replace NVRAM 0x0000C000 to 0x0000FEFF; string with space string.

    Code:
    ..
    
    $str="NVRAM 0x0000C000 to 0x0000FEFF;asdweqrc";
    $str =~ s/[NVRAM]\s+0[xX][0-9a-fA-F]\s+[to]\s+0[xX][0-9a-fA-F]//g;
    printf("str=$str");
    output should be only this string == asdweqrc
  • rellaboyina
    New Member
    • Jan 2007
    • 55

    #2
    Originally posted by lokeshrajoria
    Hello Everyone,
    here i am posting regax prob. can anybody tell me why is not working. i want replace NVRAM 0x0000C000 to 0x0000FEFF; string with space string.

    Code:
    ..
    
    $str="NVRAM 0x0000C000 to 0x0000FEFF;asdweqrc";
    $str =~ s/[NVRAM]\s+0[xX][0-9a-fA-F]\s+[to]\s+0[xX][0-9a-fA-F]//g;
    printf("str=$str");
    output should be only this string == asdweqrc
    You can achieve the result in 2 ways:

    1) using split function as

    Code:
    my $str="NVRAM 0x0000C000 to 0x0000FEFF;asdweqrc";
    my @strings = split(/;/,$str);
    print "result = $strings[1]";
    2) using the regex as you have asked

    Code:
    my $str="NVRAM 0x0000C000 to 0x0000FEFF;asdweqrc";
    $str =~ s/(.*);(\w+)/$2/gi;
    print "result = $str";

    Comment

    Working...