[英]RegExp Match PHP
Data: 数据:
N15319542045C13_1_3/61488007C13-130083_1_3/61488007C13-130083-1_1_3/P1197443641_1_3SD|1
NP1196939393_1_3SU|OD=2/7;|BNP1196939393_1_3SU|OD=2/7;|BNP1196930222_1_3SU|OD=4/11;|
NP1196930222_1_3SU|OD=4/11;|
N15319384625C13_1_3/61445794C13-130077_1_3SD||BN15319384625C13_1_3/61445794C13-130077_1_3SD||
RegExp: RegExp:
(N(.*?)S([UID])\|(.*?))(?:B|\|.?$)
I am trying to find 7 matches using above regex but only 6 are matching. 我试图使用上述正则表达式找到7个匹配项,但只有6个匹配。 Not sure how to fix to match 1st line as well.
不确定如何解决以匹配第一行。
Format: 格式:
N(key)S(action)|(value or end)
end depend on different matches 结束取决于不同的比赛
I solved it if someone else needs: 如果有人需要,我就解决了:
(\x15(.*?)\x01([UID])\|(.*?))(?:.*?\x08|.*\|?$)
The regex didn't work because after the S[UID]
you expect 2 |
正则表达式不起作用,因为在
S[UID]
您期望2 |
as per the regex but in the first input string there is only one. 按照正则表达式,但是在第一个输入字符串中只有一个。
One fix is to make the second group optional and move out the string end anchor $
一种解决方法是使第二组可选,并移出字符串末锚
$
(N(.*?)S([UID])\|(.*?))(?:B|\|.?)?$
N.*?S[UID]\\|.*$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.