Techno Blender
Digitally Yours.

Extracting all present dates in any given String using Regular Expressions

0 47


import java.io.*;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

  

public class GFG {

  

    

    public static void main(String[] args)

    {

  

        

        String str

            = "The First Version was released on 12-07-2008."

              + "Next Release will might come on 12 July 2009. "

              + "The due date for paymnet is  2023-09-1."

              + "India gained its freedom on 15 August 1947 which was a Friday."

              + "Republic Day is a public holiday in India where the country marks and celebrates "

              + "the date on which the Constitution of India came into effect on 26-1-1950.";

  

        

        

        

        String strPattern[] = {

            "\\d{2}-\\d{2}-\\d{4}",

            "[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{4}",

            "\\d{1, 2}-(January|February|March|April|May|June|July|August|September|October|November|December)-\\d{4}",

            "\\d{4}-\\d{1, 2}-\\d{1, 2}",

            "[0-9]{1, 2}\\s(January|February|March|April|May|June|July|August|September|October|November|December)\\s\\d{4}",

            "\\d{1, 2}-\\d{1, 2}-\\d{4}"

        };

  

        for (int i = 0; i < strPattern.length; i++) {

            Pattern pattern

                = Pattern.compile(strPattern[i]);

            Matcher matcher = pattern.matcher(str);

            while (matcher.find()) {

                System.out.println(matcher.group());

            }

        }

    }

}


import java.io.*;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

  

public class GFG {

  

    

    public static void main(String[] args)

    {

  

        

        String str

            = "The First Version was released on 12-07-2008."

              + "Next Release will might come on 12 July 2009. "

              + "The due date for paymnet is  2023-09-1."

              + "India gained its freedom on 15 August 1947 which was a Friday."

              + "Republic Day is a public holiday in India where the country marks and celebrates "

              + "the date on which the Constitution of India came into effect on 26-1-1950.";

  

        

        

        

        String strPattern[] = {

            "\\d{2}-\\d{2}-\\d{4}",

            "[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{4}",

            "\\d{1, 2}-(January|February|March|April|May|June|July|August|September|October|November|December)-\\d{4}",

            "\\d{4}-\\d{1, 2}-\\d{1, 2}",

            "[0-9]{1, 2}\\s(January|February|March|April|May|June|July|August|September|October|November|December)\\s\\d{4}",

            "\\d{1, 2}-\\d{1, 2}-\\d{4}"

        };

  

        for (int i = 0; i < strPattern.length; i++) {

            Pattern pattern

                = Pattern.compile(strPattern[i]);

            Matcher matcher = pattern.matcher(str);

            while (matcher.find()) {

                System.out.println(matcher.group());

            }

        }

    }

}

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.

Leave a comment