Java - Regex extract date from string
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I need to extract date from this string:
BB inform: buy your tickect, final card number xxxx, $ 00,00, on 04/10, at 11:28. If you don't recognize call 40032 2412.
Also The full date 04/10/2015
The date pattern is dd/MM or dd/MM/yyyy
The code:
String mydata = "BB inform: buy your tickect, final card number xxxx, $ 00,00, on 04/10, at 11:28. If you don't recognize call 40032 2412.";
Pattern p = Pattern.compile("(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d");
Matcher m = p.matcher(mydata);
Result:
m.matches() == false
java regex date extract extraction
add a comment |
I need to extract date from this string:
BB inform: buy your tickect, final card number xxxx, $ 00,00, on 04/10, at 11:28. If you don't recognize call 40032 2412.
Also The full date 04/10/2015
The date pattern is dd/MM or dd/MM/yyyy
The code:
String mydata = "BB inform: buy your tickect, final card number xxxx, $ 00,00, on 04/10, at 11:28. If you don't recognize call 40032 2412.";
Pattern p = Pattern.compile("(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d");
Matcher m = p.matcher(mydata);
Result:
m.matches() == false
java regex date extract extraction
Please post a piece of code of what you have tried so far, and where you failed
– Rakesh
Nov 25 '15 at 18:21
i'm sorry, i posted now
– Pedro Fernandes
Nov 25 '15 at 18:29
add a comment |
I need to extract date from this string:
BB inform: buy your tickect, final card number xxxx, $ 00,00, on 04/10, at 11:28. If you don't recognize call 40032 2412.
Also The full date 04/10/2015
The date pattern is dd/MM or dd/MM/yyyy
The code:
String mydata = "BB inform: buy your tickect, final card number xxxx, $ 00,00, on 04/10, at 11:28. If you don't recognize call 40032 2412.";
Pattern p = Pattern.compile("(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d");
Matcher m = p.matcher(mydata);
Result:
m.matches() == false
java regex date extract extraction
I need to extract date from this string:
BB inform: buy your tickect, final card number xxxx, $ 00,00, on 04/10, at 11:28. If you don't recognize call 40032 2412.
Also The full date 04/10/2015
The date pattern is dd/MM or dd/MM/yyyy
The code:
String mydata = "BB inform: buy your tickect, final card number xxxx, $ 00,00, on 04/10, at 11:28. If you don't recognize call 40032 2412.";
Pattern p = Pattern.compile("(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d");
Matcher m = p.matcher(mydata);
Result:
m.matches() == false
java regex date extract extraction
java regex date extract extraction
edited Nov 25 '15 at 18:23
Pedro Fernandes
asked Nov 25 '15 at 18:18
Pedro FernandesPedro Fernandes
14119
14119
Please post a piece of code of what you have tried so far, and where you failed
– Rakesh
Nov 25 '15 at 18:21
i'm sorry, i posted now
– Pedro Fernandes
Nov 25 '15 at 18:29
add a comment |
Please post a piece of code of what you have tried so far, and where you failed
– Rakesh
Nov 25 '15 at 18:21
i'm sorry, i posted now
– Pedro Fernandes
Nov 25 '15 at 18:29
Please post a piece of code of what you have tried so far, and where you failed
– Rakesh
Nov 25 '15 at 18:21
Please post a piece of code of what you have tried so far, and where you failed
– Rakesh
Nov 25 '15 at 18:21
i'm sorry, i posted now
– Pedro Fernandes
Nov 25 '15 at 18:29
i'm sorry, i posted now
– Pedro Fernandes
Nov 25 '15 at 18:29
add a comment |
1 Answer
1
active
oldest
votes
You can try with this regex :
Matcher m = Pattern.compile("(\d1,2/\d1,2/\d4|\d1,2/\d1,2)", Pattern.CASE_INSENSITIVE).matcher(string);
while (m.find())
System.out.println(m.group(1));
Its looking for a pattern DD/MM or then looking for a DD/MM/YYYY.
Check this Link
It doesn't work. I guess it is because there is text before and after the date. if there is only date in the string this will work but not is my case
– Pedro Fernandes
Nov 25 '15 at 18:46
1
It worked . I copied your text and form the regex for it.
– Madushan Perera
Nov 25 '15 at 18:53
1
I can second that. I copied this code snippet and ran it against the OP's string, and it did return the date.
– Rakesh
Nov 25 '15 at 18:54
@Rakesh Thank You.
– Madushan Perera
Nov 25 '15 at 18:57
It works fine. i forgot the while loop, i'm sorry!
– Pedro Fernandes
Nov 25 '15 at 19:17
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33923741%2fjava-regex-extract-date-from-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try with this regex :
Matcher m = Pattern.compile("(\d1,2/\d1,2/\d4|\d1,2/\d1,2)", Pattern.CASE_INSENSITIVE).matcher(string);
while (m.find())
System.out.println(m.group(1));
Its looking for a pattern DD/MM or then looking for a DD/MM/YYYY.
Check this Link
It doesn't work. I guess it is because there is text before and after the date. if there is only date in the string this will work but not is my case
– Pedro Fernandes
Nov 25 '15 at 18:46
1
It worked . I copied your text and form the regex for it.
– Madushan Perera
Nov 25 '15 at 18:53
1
I can second that. I copied this code snippet and ran it against the OP's string, and it did return the date.
– Rakesh
Nov 25 '15 at 18:54
@Rakesh Thank You.
– Madushan Perera
Nov 25 '15 at 18:57
It works fine. i forgot the while loop, i'm sorry!
– Pedro Fernandes
Nov 25 '15 at 19:17
|
show 1 more comment
You can try with this regex :
Matcher m = Pattern.compile("(\d1,2/\d1,2/\d4|\d1,2/\d1,2)", Pattern.CASE_INSENSITIVE).matcher(string);
while (m.find())
System.out.println(m.group(1));
Its looking for a pattern DD/MM or then looking for a DD/MM/YYYY.
Check this Link
It doesn't work. I guess it is because there is text before and after the date. if there is only date in the string this will work but not is my case
– Pedro Fernandes
Nov 25 '15 at 18:46
1
It worked . I copied your text and form the regex for it.
– Madushan Perera
Nov 25 '15 at 18:53
1
I can second that. I copied this code snippet and ran it against the OP's string, and it did return the date.
– Rakesh
Nov 25 '15 at 18:54
@Rakesh Thank You.
– Madushan Perera
Nov 25 '15 at 18:57
It works fine. i forgot the while loop, i'm sorry!
– Pedro Fernandes
Nov 25 '15 at 19:17
|
show 1 more comment
You can try with this regex :
Matcher m = Pattern.compile("(\d1,2/\d1,2/\d4|\d1,2/\d1,2)", Pattern.CASE_INSENSITIVE).matcher(string);
while (m.find())
System.out.println(m.group(1));
Its looking for a pattern DD/MM or then looking for a DD/MM/YYYY.
Check this Link
You can try with this regex :
Matcher m = Pattern.compile("(\d1,2/\d1,2/\d4|\d1,2/\d1,2)", Pattern.CASE_INSENSITIVE).matcher(string);
while (m.find())
System.out.println(m.group(1));
Its looking for a pattern DD/MM or then looking for a DD/MM/YYYY.
Check this Link
edited Nov 25 '15 at 19:12
answered Nov 25 '15 at 18:34
Madushan PereraMadushan Perera
2,14811128
2,14811128
It doesn't work. I guess it is because there is text before and after the date. if there is only date in the string this will work but not is my case
– Pedro Fernandes
Nov 25 '15 at 18:46
1
It worked . I copied your text and form the regex for it.
– Madushan Perera
Nov 25 '15 at 18:53
1
I can second that. I copied this code snippet and ran it against the OP's string, and it did return the date.
– Rakesh
Nov 25 '15 at 18:54
@Rakesh Thank You.
– Madushan Perera
Nov 25 '15 at 18:57
It works fine. i forgot the while loop, i'm sorry!
– Pedro Fernandes
Nov 25 '15 at 19:17
|
show 1 more comment
It doesn't work. I guess it is because there is text before and after the date. if there is only date in the string this will work but not is my case
– Pedro Fernandes
Nov 25 '15 at 18:46
1
It worked . I copied your text and form the regex for it.
– Madushan Perera
Nov 25 '15 at 18:53
1
I can second that. I copied this code snippet and ran it against the OP's string, and it did return the date.
– Rakesh
Nov 25 '15 at 18:54
@Rakesh Thank You.
– Madushan Perera
Nov 25 '15 at 18:57
It works fine. i forgot the while loop, i'm sorry!
– Pedro Fernandes
Nov 25 '15 at 19:17
It doesn't work. I guess it is because there is text before and after the date. if there is only date in the string this will work but not is my case
– Pedro Fernandes
Nov 25 '15 at 18:46
It doesn't work. I guess it is because there is text before and after the date. if there is only date in the string this will work but not is my case
– Pedro Fernandes
Nov 25 '15 at 18:46
1
1
It worked . I copied your text and form the regex for it.
– Madushan Perera
Nov 25 '15 at 18:53
It worked . I copied your text and form the regex for it.
– Madushan Perera
Nov 25 '15 at 18:53
1
1
I can second that. I copied this code snippet and ran it against the OP's string, and it did return the date.
– Rakesh
Nov 25 '15 at 18:54
I can second that. I copied this code snippet and ran it against the OP's string, and it did return the date.
– Rakesh
Nov 25 '15 at 18:54
@Rakesh Thank You.
– Madushan Perera
Nov 25 '15 at 18:57
@Rakesh Thank You.
– Madushan Perera
Nov 25 '15 at 18:57
It works fine. i forgot the while loop, i'm sorry!
– Pedro Fernandes
Nov 25 '15 at 19:17
It works fine. i forgot the while loop, i'm sorry!
– Pedro Fernandes
Nov 25 '15 at 19:17
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33923741%2fjava-regex-extract-date-from-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please post a piece of code of what you have tried so far, and where you failed
– Rakesh
Nov 25 '15 at 18:21
i'm sorry, i posted now
– Pedro Fernandes
Nov 25 '15 at 18:29