[英]how to grep the word between symbols using perl
我需要在符号之间插入如下所示的数字。
my $string = "hi how r u<what is your name>what is your age";
我需要grep as
$str = what is yourname;
或者,在Perl中:
$string =~ /\?(.+)\?/;
$result = $1;
您可以使用下面的捕获组。
use strict;
use warnings;
my $line = "hi how r u?what is your name?what is your age";
my @str = $line =~ m/\?([^?]*)\?/g;
print "@str\n";
输出:
what is your name
您可以在此元字符上拆分字符串。
my @results = split /\?/, $string;
print $results[1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.