- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2617 Articles for Java
233 Views
This class matches hexa-decimal characters i.e. [0-9a-fA-F].Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SpaceCharacters { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{XDigit}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count = 0; ... Read More
622 Views
If you want to specify the number of occurrences while constructing a regular expression you can use quantifiers. Java supports three types of quantifiers namely: greedy quantifiers, reluctant quantifiers and possessive quantifiers.Greedy quantifiers − Greedy quantifiers are the default quantifiers. A greedy quantifier matches as much as possible from the input string (longest match possible) if match not occurred it leaves the last character and matches again.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter input text: "); ... Read More
837 Views
This class matches all the printable characters.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PrintableCharacters { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{Print}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count = 0; ... Read More
394 Views
This class matches all visible characters i.e. alphabets, digits, punctuation marks.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class VisiblieCharacters { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{Graph}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); ... Read More
3K+ Views
This class matches punctuation marks. i.e.!"#$%&'()*+, -./:;?@[\]^_`{|}~Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class AlphanumericExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{Punct}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count = 0; ... Read More
499 Views
This class matches alpha numeric characters.Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class AlphanumericExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{Alnum}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count = 0; ... Read More
253 Views
This class matches decimal digits 0 to 9.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class DigitsExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{Digit}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count = ... Read More
502 Views
This class matches alphabetic characters both upper case and smaller case.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main( String args[] ) { //Regular expression to match lower case letters String regex = "^\p{Alpha}+$"; //Getting the input data Scanner sc = new Scanner(System.in); System.out.println("Enter 5 input strings: "); String input[] = new String[5]; for (int i=0; i
591 Views
This class matches the ASCII characters i.e. \x00-\x7F.Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "^[\p{ASCII}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count = 0; ... Read More
200 Views
The CharMatcher class determines a true or false value for any Java char value, just as Predicate does for any Object.Sr.NoMethods & Description1CharMatcher and(CharMatcher other)Returns a matcher that matches any character matched by both this matcher and other.2static CharMatcher anyOf(CharSequence sequence)Returns a char matcher that matches any character present in the given character sequence.3boolean apply(Character character)Deprecated. Provided only to satisfy the Predicate interface; use matches(char) instead.4String collapseFrom(CharSequence sequence, char replacement)Returns a string copy of the input character sequence, with each group of consecutive characters that match this matcher replaced by a single replacement character.5int countIn(CharSequence sequence)Returns the number of matching ... Read More