Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.*;
- import java.util.*;
- import java.io.*;
- import java.text.*;
- import java.time.*;
- import java.time.format.DateTimeFormatter;;
- public class Main {
- public static void main(String[] args) throws Exception{
- String daty = "2007-01-12Jakis txt2008-01-31 xxx 2008-02-29 2008-15-10 2008-19-45 2009-05-01\\n 20999-11-11 pppp 2001-00-01 09-01-01 2001-01-00 2009-01-111 2009-02-29 1998-11-11";
- String regex = "(?<year>1[0-9][0-9][0-9]|2[0-9][0-9][0-9]|3[0-9][0-9][0-9]|4[0-9][0-9][0-9]|5[0-9][0-9][0-9]|6[0-9][0-9][0-9]|7[0-9][0-9][0-9]|8[0-9][0-9][0-9]|9[0-9][0-9][0-9])"
- + "-?(?<month>1[0-2]|0[1-9])"
- + "-?(?<day>3[01]|0[1-9]|[12][0-9])(?!\\d+)";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(daty);
- String result = "";
- while(matcher.find()) {
- result += matcher.group() + '\n';
- }
- if (result.contentEquals(""))result = "Brak danych";
- System.out.print(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement