[英]how to grep the word between symbols using perl
I need to grep the word between the symbols as shown below in an array. 我需要在符号之间插入如下所示的数字。
my $string = "hi how r u<what is your name>what is your age";
i need to grep as 我需要grep as
$str = what is yourname;
Or, in Perl: 或者,在Perl中:
$string =~ /\?(.+)\?/;
$result = $1;
You could use capturing groups like below. 您可以使用下面的捕获组。
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";
Output: 输出:
what is your name
You can split your string on this metacharacter. 您可以在此元字符上拆分字符串。
my @results = split /\?/, $string;
print $results[1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.