Click here to Skip to main content
15,891,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 9-Sep-16 3:07am

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.
 
Share this answer
 
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]

Advice: Use last link and build the RegEx from scratch, your actual RegEx is a mess.
 
Share this answer
 
v2
Comments
Member 12729590 9-Sep-16 9:38am    
Can you make one as I am a beginner in Java , hope you don't mind
Patrice T 9-Sep-16 10:10am    
Give a try to last link and start with
DATE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900