Java Regex Pattern Example

Regex [Regular Expression]:

Regular expression is a useful one to match and extract only the required parts.
Defining the phone number formats.
Removing unreadable or unwanted characters from a string

Sample Program:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Regex {
	public static void main(String[] args) {
		String inputStr = "?'s a technical,java-blog";
		Pattern pattern = Pattern.compile("[\\s\\?\\,\\-\\']+");
		Matcher matcher = pattern.matcher(inputStr);
		boolean temp = matcher.find();
		if (temp) {
			String aftRegex = inputStr.replaceAll("[\\s\\?\\,\\-\\']+", "_");
		} else {





Recommended Java Books:

754 total views, 1 views today

About Mirthbees 677 Articles
Blogger, Innovator, Developer and Enterpreneur. Founder of GuruRecharge, Readymade online recharge script. Lead Developer in

Be the first to comment

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.