0

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

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by DJSAN10
0

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?

Edited by DavidKroukamp: n/a

0

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 :)

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.