【发布时间】:2020-12-12 12:10:50
【问题描述】:
我正在尝试从旧的 DOS 转储中匹配用户,以便他们可以迁移到新的东西。它们以% 符号开头,以] 结尾。一些在一条线上,另一些则跨越多条线。
https://regex101.com/r/0h5ndW/1
我的正则表达式%([^\%]*)] 有效,但是有没有更好的方法来选择从% 到](包括% 和])的每个用户,这样我就可以让他们通过preg_replace并在以后操纵它们?
我对多线部分有点怀疑。
Expected Output
%user:100 [ type=admin, added=10/12/1997, last-login:10/20/1997, total-logins:45, status:1 ]
%user:111 [ type=user, added=10/12/1997, last-login:10/27/1997, total-logins:145, status:1 ]
%user:112 [ type=viewer, added=10/12/1997, last-login:10/23/1997, total-logins:6, status:1 ]
%user:113 [ type=viewer, added=10/12/1997, last-login:10/14/1997, total-logins:2, status:1]
%user:114 [ type=viewer, added=10/12/1997, last-login:10/14/1997, total-logins:1, status:1]
%user:115 [ type=viewer, added=10/12/1997, last-login:10/12/1997, total-logins:1, status:1 ]
原始数据
%user:100 [
type=admin,
added=10/12/1997,
last-login:10/20/1997,
total-logins:45,
status:1
]
%user:111 [
type=user,
added=10/12/1997,
last-login:10/27/1997,
total-logins:145,
status:1
]
%user:112 [ type=viewer, added=10/12/1997,
last-login:10/23/1997,
total-logins:6,
status:1
]
%user:113 [ type=viewer, added=10/12/1997, last-login:10/14/1997, total-logins:2, status:1]
%user:114 [ type=viewer, added=10/12/1997, last-login:10/14/1997, total-logins:1,
status:1]
%user:115 [ type=viewer, added=10/12/1997, last-login:10/12/1997, total-logins:1,
status:1
]
【问题讨论】: