Pattern COMMENTS field in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 06:07:37

388 Views

The COMMENTS field of the Pattern class allows whitespace and comments in pattern. When you use this as flag value to the compile() method, white spaces and, comments starting with # are ignored in the given pattern.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class COMMENTES_Example {    public static void main( String args[] ) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input data: ");       String input = sc.nextLine();       //Regular expression to find digits       String regex = "\d #ignore this comment";       //Compiling ... Read More

Pattern CASE_INSENSITIVE field in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 06:05:24

1K+ Views

This CASE_INSENSITIVE field of the Pattern class matches characters irrespective of case. When you use this as flag value to the compile() method and if you search for characters using regular expressions characters of both cases will be matched.Note − By default, this flag matches only ASCII charactersExample 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CASE_INSENSITIVE_Example {    public static void main( String args[] ) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input data: ");       String input = sc.nextLine();       System.out.println("Enter required character: ");       char ... Read More

Pattern flags() method in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 05:59:25

370 Views

The pattern class of java.regex package is a compiled representation of a regular expression.The compile() method of this class accepts a string value representing a regular expression and returns a Pattern object, the following is the signature of this method.static Pattern compile(String regex)Another variant of this method accepts an integer value representing flags, following is the signature of the compile method with two parameters.static Pattern compile(String regex, int flags)The Pattern class provides various fields each representing a flagS.NoField and Description1CANON_EQMatches two characters only if they are canonically equal.2CASE_INSENSITIVEMatches characters irrespective of case.3COMMENTSAllows whitespace and comments in pattern.4DOTALLEnables dotall mode. Where ... Read More

Pattern toString() method in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 05:54:48

112 Views

The Pattern class of the java.util.regex package is a compiled representation of a regular expression.The toString() method of this class returns the string representation of the regular expression using which the current Pattern was compiled.Example1import java.util.Scanner; import java.util.regex.Pattern; public class Example {    public static void main( String args[] ) {       //Reading string value       Scanner sc = new Scanner(System.in);       System.out.println("Enter input string");       String input = sc.nextLine();       //Regular expression to find digits       String regex = "(\d)";       //Compiling the regular expression ... Read More

Pattern splitAsStream() method in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 05:52:46

208 Views

The Pattern class of the java.util.regex package is a compiled representation of a regular expression.The splitAsStream() method of this class accepts a CharSequence object, representing the input string as a parameter and, at each match, it splits the given string into a new substring and returns the result as a stream holding all the substrings.Exampleimport java.util.regex.Pattern; import java.util.stream.Stream; public class SplitAsStreamMethodExample {    public static void main( String args[] ) {       //Regular expression to find digits       String regex = "(\s)(\d)(\s)";       String input = " 1 Name:Radha, age:25 2 Name:Ramu, age:32" + ... Read More

Pattern split() method in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 05:51:14

431 Views

The Pattern class of the java.util.regex package is a compiled representation of a regular expression.The split() method of this class accepts a CharSequence object, representing the input string as a parameter and, at each match, it splits the given string into a new token and returns the string array holding all the tokens.Exampleimport java.util.regex.Pattern; public class SplitMethodExample {    public static void main( String args[] ) {       //Regular expression to find digits       String regex = "(\s)(\d)(\s)";       String input = " 1 Name:Radha, age:25 2 Name:Ramu, age:32 3 Name:Rajev, age:45";     ... Read More

Pattern pattern() method in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 05:47:04

1K+ Views

The java.util.regex package of java provides various classes to find particular patterns in character sequences. The pattern class of this package is a compiled representation of a regular expression.The pattern() method of the Pattern class fetches and returns the regular expression in the string format, using which the current pattern was compiled.Example 1import java.util.regex.Pattern; public class PatternExample {    public static void main(String[] args) {       String date = "12/09/2019";       String regex = "^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$";       //Creating a pattern object       Pattern pattern = Pattern.compile(regex);       if(pattern.matcher(date).matches()) {     ... Read More

Pattern matches() method in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 05:44:56

428 Views

The java.util.regex package of java provides various classes to find particular patterns in character sequences. The pattern class of this package is a compiled representation of a regular expression.The matches() method of the Pattern class accepts −A string value representing the regular expression.An object of the CharSequence class representing the input string.On invocation, this method matches the input string against the regular expression. This method returns a boolean value which is true in-case of a match else, false.Exampleimport java.util.Scanner; import java.util.regex.Pattern; public class MatchesExample {    public static void main(String[] args) {       //Getting the date     ... Read More

Pattern quote() method in Java with examples

Maruthi Krishna
Updated on 20-Nov-2019 05:42:59

1K+ Views

The java.util.regex package of java provides various classes to find particular patterns in character sequences.The pattern class of this package is a compiled representation of a regular expression. The quote() method of this class accepts a string value and returns a pattern string that would match the given string i.e. to the given string additional metacharacters and escape sequences are added. Anyway, the meaning of the given string is not affected.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class QuoteExample {    public static void main( String args[] ) {       //Reading string value       Scanner ... Read More

Facebook Marketing Strategy 2020 You Should Implement for Your Business

Samual Sam
Updated on 19-Nov-2019 12:12:56

85 Views

Facebook’s power as a marketing platform to draw online customers can be inferred from the following statistics −The social media giant has 2.32 billion users across the globe.As of today, 60 million businesses are existing on this social media platform.39% of customers follow a company’s Facebook page to view their offers and discounts.That is the reason many B2C businesses focus dedicatedly on Facebook marketing to strengthen and expand their businesses.It is no wonder that creating a Facebook page for a business is very important for its existence because this is an excellent way to take business closer to the heart ... Read More

Advertisements