我有一个字符串,字符串的一些内容用双引号括起来。
例如:
test_case_be "+test+tx+rx+path"
对于上述输入,我想将整个字符串分成两部分:
test_case_be
之外的字符串] 我要存储在$temp1
. +test+tx+rx+path
] 我想把它存储在 $temp2
. 有人可以帮助我提供有关如何执行上述操作的示例代码吗?
最佳答案
这可以做到:
my $input_string = qq(test_case_be "+test+tx+rx+path");
my $re = qr/^([^"]+)"([^"]+)"/;
# Evaluating in list context this way affects the first variable to the
# first group and so on
my ($before, $after) = ($input_string =~ $re);
print <<EOF;
before: $before
after: $after
EOF
输出:
before: test_case_be
after: +test+tx+rx+path
关于Perl:读取字符串中双引号之间的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14270748/