[英]looking for a regex to match a specific pattern
I need to get rid of date formats in over 6000 lines of code. 我需要在超过6000行代码中删除日期格式。 The format is always the same, but dates and times will vary including AM/PM.
格式始终相同,但日期和时间将有所不同,包括AM / PM。
This is the pattern 这是模式
[10/6/17, 11:13:52 AM] [10/6/17,上午11:13:52]
So far I used 到目前为止我用过
.+?(?=[0-9])
which grabs numbers but now I am stuck. 抓住数字,但现在我被卡住了。 Can anyone help?
有人可以帮忙吗? Thanks!
谢谢!
It depends on how strict you need to be and the boundary conditions. 这取决于你需要多严格和边界条件。 Something like
就像是
\[\d{1,2}\/\d{1,2}\/\d{1,2}, \d{1,2}:\d{2}:\d{2} \w{2}\]
should do it. 应该这样做。
Btw, regex101.com is an awesome tool for debuging regexs 顺便说一句, regex101.com是一款用于调试正则表达式的绝佳工具
This should match your dates : 这应符合您的日期:
\[\d{1,2}/\d{1,2}/\d{1,2}, \d{1,2}:\d{1,2}:\d{1,2} [AP]M\]
Note that depending on the language you might need to escape the /
. 请注意,根据您可能需要的语言来逃避
/
。
Try it here . 在这里试试吧 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.