Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 用于在多个管道中收集文本的正则表达式_Regex_Perl_Pcre_Regex Lookarounds - Fatal编程技术网

Regex 用于在多个管道中收集文本的正则表达式

Regex 用于在多个管道中收集文本的正则表达式,regex,perl,pcre,regex-lookarounds,Regex,Perl,Pcre,Regex Lookarounds,我需要在管道之间匹配文本。我试过\\\\\\\\[^ 124;]+\\\\\\\\\\\,但似乎并没有收集到每一个 |N/A|text123|text1235|Medium|1|Medium|test123|test456|test|test|test|http|tcp| 这看起来像是一份工作: 输出: N/A text123 text1235 Medium 1 Medium test123 test456 test test test http tcp 就正则表达式而言,这应该是可行的:

我需要在管道之间匹配文本。我试过
\\\\\\\\[^ 124;]+\\\\\\\\\\\
,但似乎并没有收集到每一个

|N/A|text123|text1235|Medium|1|Medium|test123|test456|test|test|test|http|tcp|
这看起来像是一份工作:

输出:

N/A
text123
text1235
Medium
1
Medium
test123
test456
test
test
test
http
tcp
就正则表达式而言,这应该是可行的:

my @items = /[^|]+/g;
试试这个:

    [^\|]+

也就是说,匹配除了管道以外的任何东西

那么只匹配
/[^ |]+/g
呢?你的环境是什么?请共享失败的当前代码。这将仅获取第一个匹配项。你需要
/g
(全局)修饰符来获得所有匹配项(我相信这就是OP所要求的)。哦,是的。有道理。我正在使用默认设置的/g进行调试。谢谢<代码>我的@items=split/\|/,$string;班次(@项)或<代码>我的@items=split/\\|/,substr($string,1)来解释前导的
|
。或
shift@items
允许没有前导的
|
    [^\|]+