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

Recommended Answers

All 3 Replies

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?

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.