这个java正则表达式有什么不对 [英] Whats wrong in this java regex

查看:82
本文介绍了这个java正则表达式有什么不对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我在java的正则表达式中有什么错误,matcher.find与它不匹配。我要匹配的字符串是----- DATEADD('2016-09-18T00:00:00','year','1')



正在使用的正则表达式是



1)^ [DATEADD] \\([\\'] [\\w - :] + [ \\ '] [\\,] [\\'] [A-ZA-Z _] [\\ '] [\\,] [\\'] [\\ \\\d] + [[\\']] [\\]] $

2)^ [DATEADD] [\\(] [\\\\ ] * [] [A-ZA-Z0-9 _。] + [...] [A-ZA-Z _] [...] [\\d] + [[\\']] [\\\\] * [\\]] $



我尝试了什么:



我尝试了很多正则表达式,但没有一个匹配

Can anybody please tell me whats wrong in the regex for java the matcher.find is not matching it. My string to match is this ----- DATEADD('2016-09-18T00:00:00','year','1' )

The regex I am using is

1)^[DATEADD]\\([\\'][\\w-:]+[\\'][\\,][\\'][a-zA-Z_][\\'][\\,][\\'][\\d]+[[\\']][\\)]$
2)^[DATEADD][\\(][\\s]*[.][a-zA-Z0-9_.]+[...][a-zA-Z_][...][\\d]+[[\\']][\\s]*[\\)]$"

What I have tried:

I have tried a lot of regex but none of them are matching

推荐答案



2 )^ [DATEADD] [\\(] [\\s] * [] [A-ZA-Z0-9 _。] + [...] [A-ZA-Z _] [... ] [\\d] + [[\\']] [\\\\] * [\\]]

2)^[DATEADD][\\(][\\s]*[.][a-zA-Z0-9_.]+[...][a-zA-Z_][...][\\d]+[[\\']][\\s]*[\\)]






我尝试了什么:



我已经尝试了很多正则表达式,但没有一个匹配
"

What I have tried:

I have tried a lot of regex but none of them are matching


好......首先要注意的是'''和']'分隔可以在一个位置的字符集合。例如,[0123456789]或[0-9]将匹配单个数字。

因此[DATEADD]将匹配单个字符'A','D ','E'或'T' - 而不是一系列字符。

要匹配序列DATEADD,只需键入不带方括号的字符。

请看这里: Pattern(Java Platform SE 7) [ ^ ] - 它可能会有所帮助。

并获得 Expresso 的副本[ ^ ] - 它是免费的,它会检查并生成正则表达式。
OK...the first thing to note is that '[' and ']' delimit a collection of characters that can be in a single location. For example "[0123456789]" or "[0-9]" will each match a single digit.
So "[DATEADD]" will match a single character that is an 'A', 'D', 'E', or 'T' - and not a sequence of characters.
To match the sequence "DATEADD" just type the characters without the square brackets.
Have a look here: Pattern (Java Platform SE 7 )[^] - it may help.
And get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.


这篇关于这个java正则表达式有什么不对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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