I think you'd want that RE within an if condition, because otherwise the RE could fail to match and you'd load the previous value of $1 into $var
#!/usr/bin/perl use warnings; use strict; my $str = "http://172.20.37.115:8080/se/1.0/provision/subscribers/1989 +68"; $str =~ /.*\/(\d+)$/; my $var = $1 || ''; print "$var\n"; # prints 198968 my $str2 = http://172.20.37.115:8080/se/1.0/provision/subscribers/foo" +; $str2 =~ /.*\/(\d+)$/; my $var2 = $1 || ''; print "$var2\n"; #prints 198968
May be better to do:
use warnings; use strict; my $str = "http://172.20.37.115:8080/se/1.0/provision/subscribers/1989 +68"; if( $str =~ /.*\/(\d+)$/ ) { my $var = $1 || ''; print "$var\n"; }
In reply to Re^2: how to find particular string and store in to variable
by 1nickt
in thread how to find particular string and store in to variable
by bhushanQA
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |