请问合并日期字段的正则表达式是什么? [英] what's the regular expression for a combined date field please?

查看:163
本文介绍了请问合并日期字段的正则表达式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含这些日期格式的专栏。
7Feb2008
12Feb2008

我已经尝试了(\d +)(\ w +)(\d +)这些不起作用。< br>
我知道(\d +)(\ w +)(\d +)适用于2008年2月7日
2008年2月12日

但是只要间距是除去。它停止了工作。我认为问题可能在于它不知道什么是使用的分隔符。

非常感谢任何人可以给予的任何帮助/建议。

恩典


< br>



I have a column with these date formats.
7Feb2008
12Feb2008

I've tried (\d+)(\w+)(\d+) which doesnt work.

I know that (\d+) (\w+) (\d+) works for
07 Feb 2008
12 Feb 2008

but as soon as the spacings are removed. it stopped working.  I think the problem might be that it's not knowing what's the delimeter used.

thanks a lot to any help/suggestions anyone can give.

grace








推荐答案

( \ + +)(\ w +)(\d +)与字符串匹配,所以我认为你的问题是中间组(\w +)捕获的不仅仅是月份。对于02Feb2008的目标字符串,第一个(\d +)正确匹配日,但(\w +)捕获"Feb200"。留下"8"和"8"。为决赛(\d +)。

对表达式稍作修正可解决问题:(\d +)(\ w +?)(\d +)

A slight correction to the expression solves the problem: (\d+)(\w+?)(\d+)

解析器的问题在于有很多方法可以让你满意原始表达。除非另有说明,否则默认值是从左侧匹配尽可能多的字符。由于(\w +)同时采用字母和数字,因此解析器尽可能多地挖掘,同时仍然满足整体表达式。这就是为什么最后一组中只有一个数字的原因。通过添加?对于中间组,我们告诉解析器为该组分配最小数量的字符,同时仍然将表达式作为一个整体匹配。

The problem for the parser is that there are many ways of satisfying your original expression. The default it takes is to match as many characters as possible from the left unless told otherwise. Since (\w+) takes both letters and digits, the parser scoops up as many as it can while still satisfying the overall expression. That's why there is only a single digit in the last group. By adding the ? to the middle group, we're telling the parser to assign the minimum number of characters to this group while still matching the expression as a whole.

在这种情况下还有其他表达式也适用但这个表达式最简单。

There are other expressions that will also work in this case but this one is the simplest.

Ed McElroy

Ed McElroy


这篇关于请问合并日期字段的正则表达式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆