954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Java Regex problem

I want to create a regular expression that matches with the string
"B. Hello" or "C. Hello" and so on..

I tried number of things and finally came up with this

String REGEX = "[A-Za-z]"+Pattern.quote(".")+" Hello";


but still no luck.. I tries using '\s' for space but still not working. Can anybody help me out with this. Ultimately , i need to do something like this

if("B. Hello".equals(REGEX))
		System.out.println("Hello ,B ");


Thank you

DJSAN10
Posting Whiz in Training
249 posts since Dec 2010
Reputation Points: 38
Solved Threads: 26
 

I want to create a regular expression that matches with the string "B. Hello" or "C. Hello" and so on..

I tried number of things and finally came up with this

String REGEX = "[A-Za-z]"+Pattern.quote(".")+" Hello";

but still no luck.. I tries using '\s' for space but still not working. Can anybody help me out with this. Ultimately , i need to do something like this

if("B. Hello".equals(REGEX))
		System.out.println("Hello ,B ");

Thank you


see here: http://www.vogella.de/articles/JavaRegularExpressions/article.html and here: http://mindprod.com/jgloss/regex.html
but why not use a simple if statement to separate the input into what you want?

DavidKroukamp
Practically a Master Poster
Team Colleague
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
 
see here: http://www.vogella.de/articles/JavaR...s/article.html and here: http://mindprod.com/jgloss/regex.html but why not use a simple if statement to separate the input into what you want?

Hey, thanks. Co incidently , I bumped into these same tutorials just now.Was just checking them out. :) :)but why not use a simple if statement to separate the input into what you want?
These are just some enhancements that i need to add in a previous code. I am bound to use regex,so not going for any other option at this moment . Anyway, thanks :)

DJSAN10
Posting Whiz in Training
249 posts since Dec 2010
Reputation Points: 38
Solved Threads: 26
 

Okay, problem solved. Used matches() instead of equals() :) Thanks again

DJSAN10
Posting Whiz in Training
249 posts since Dec 2010
Reputation Points: 38
Solved Threads: 26
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You