java正则表达式 提取日期,Java - 使用正则表达式失败从字符串中提取日期 (Java - extract date from string using regex- failing)...

A date pattern recognition algorithm to not only identify date pattern but also fetches probable date in Java date format. This algorithm is very fast and lightweight. The processing time is linear and all dates are identified in a single pass. Algorithm resolves date using tree traverse mechanism. Tree data structures are custom created to build supported date, time and month patterns.

The algorithm also acknowledges multiple space characters in between Date literals. E.g. DD DD DD and DD DD DD are considered as valid dates.

Following date-patterns are considered as valid and are identifiable using this algorithm.

dd MM(MM) yy(yy) yy(yy) MM(MM) dd MM(MM) dd yy(yy)

Where M is month literal is alphabet format like Jan or January

Allowed delimiters between dates are '/', '\', ' ', ',', '|', '-', ' '

It also recognizes trailing time pattern in following format hh(24):mm:ss.SSS am / pm hh(24):mm:ss am / pm hh(24):mm:ss am / pm

Resolution time is linear, no pattern matching or brute force is used. This algorithm is based on tree traversal and returns back, the list of date with following three components - date string identified in the text - converted & formatted date string - SimpleDateFormat

Using date string and the format string, users are free to convert the string into objects based on their requirements.

The algorithm library is available at maven central.

net.rationalminds

DateParser

0.3.0

The sample code to use this is below.

import java.util.List;

import net.rationalminds.LocalDateModel;

import net.rationalminds.Parser;

public class Test {

public static void main(String[] args) throws Exception {

Parser parser=new Parser();

List dates=parser.parse("Identified date :'2015-January-10 18:00:01.704', converted");

System.out.println(dates);

}

}

Output: [LocalDateModel{originalText=2015-january-10 18:00:01.704, dateTimeString=2015-1-10 18:00:01.704, conDateFormat=yyyy-MM-dd HH:mm:ss.SSS, start=18, end=46}]

The complete source is available on GitHub at https://github.com/vbhavsingh/DateParser

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值