有没有办法对这些信息进行正则表达式。
我正在尝试使用单个正则表达式从下面的行中检索日期。下面字符串中的日期和时间可以更改。
My Birthday is: Thu Jan 12 23:59:59 GMT 2012.
如果我使用这个正则表达式
(?<=My Birthday is: ).+?(?=\.)
它会给我这个。
Thu Jan 12 23:59:59 GMT 2012
但我正在寻找这个..
Thu Jan 12 2012
我如何使用与 .NET 一起使用的单个正则表达式语句来实现这一点
I'm trying to retrieve the date from the line below using a single regEX. The date and time in the string below can change.
My Birthday is: Thu Jan 12 23:59:59 GMT 2012.
If I use this regEX
(?<=My Birthday is: ).+?(?=\.)
It will give me this.
Thu Jan 12 23:59:59 GMT 2012
But I'm looking for this..
Thu Jan 12 2012
How would I accomplish that with a single Regex Statement that works with .NET
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所追求的正则表达式如下所示:
然后,您只需通过引用两个捕获的组各自的索引来连接它们即可。我不了解 .NET,但在 JavaScript 中它看起来像这样:
您可能需要在正则表达式中更改的一件事是第一个
\d\d
,具体取决于 1–显示 9 个。如果它们显示为 1–9(而不是 01–09),您需要使用\d\d?
代替。The regular expression you're after looks like this:
You'll then simply need to join the two captured groups by referencing their respective indexes. I don't know .NET, but it'd look like this in JavaScript:
The one thing you may need to change in the regular expression is the first
\d\d
, depending on how 1–9 are displayed. If they're displayed as 1–9 (rather than 01–09) you'll need to use\d\d?
instead.