drcmue4619 2017-01-17 04:03
浏览 75

RegEx匹配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:

(N(.*?)S([UID])\|(.*?))(?:B|\|.?$)

I am trying to find 7 matches using above regex but only 6 are matching. 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|.*\|?$)
  • 写回答

1条回答

  • dongzhong5756 2017-01-17 04:08
    关注

    The regex didn't work because after the S[UID] you expect 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|\|.?)?$
    

    Regex Demo


    Or may be more simpler as
    N.*?S[UID]\|.*$
    

    Regex Demo

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程