 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maruthi Krishna has Published 870 Articles
 
 
							Maruthi Krishna
188 Views
The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters. For example, the regular expression [abc] matches a single character a or, b or, c.The range variant of the character class ... Read More
 
 
							Maruthi Krishna
3K+ Views
The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters.For example the regular expression [abc] matches a single character a or, b or, c. Similarly, "[a-z]" matches a single character from ... Read More
 
 
							Maruthi Krishna
949 Views
To match/search a input data with multiple lines −Get the input string.Split it into an array of tokens by passing "\r?" as parameter to the split method.Compile the required regular expression using the compile() method of the pattern class.Retrieve the matcher object using the matcher() method.In the for loop find ... Read More
 
 
							Maruthi Krishna
155 Views
The split() method of the String class accepts a regular expression, splits the current input text into tokens and returns them as a string array.Example Live Demoimport java.util.Scanner; public class Example{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter input ... Read More
 
 
							Maruthi Krishna
3K+ Views
Named capturing groups allows you to reference the groups by names. Java started supporting captured groups since SE7.Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ReplaceAll{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter input text: "); ... Read More
 
 
							Maruthi Krishna
1K+ Views
Once you compile the required regular expression and retrieved the matcher object by passing the input string as a parameter to the matcher() method.You can replace all the matched parts of the input string with another str4ing using the replaceAll() method of the Matcher class.This method accepts a string (replacement ... Read More
 
 
							Maruthi Krishna
312 Views
To match a pattern within another match you need to compile the regular expression to match the outer pattern find the match retrieve the results and pass the results as input to the inner Matcher object.Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherExample { public static void ... Read More
 
 
							Maruthi Krishna
11K+ Views
Java does not provide any method to retrieve the list of all matches we need to use Lists and add the results to it in the while loop.Example Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ListOfMatches{ public static void main(String[] args) { ... Read More
 
 
							Maruthi Krishna
1K+ Views
The start() method of the java.util.regex.Matcher class returns the starting position of the match (if a match occurred).Similarly, the end() method of the Matcher class returns the ending position of the match.Therefore, return value of the start() method will be the starting position of the match and the difference between ... Read More
 
 
							Maruthi Krishna
2K+ Views
The meta character "\b" matches word boundaries. i.e. it matches before the first and after the last word characters and between word and non-word characters.Therefore to match a whole word you need to surround it between the word boundary meta characters as −\btest\bExample Live DemoFollowing Java example counts and prints the ... Read More
