I need help with my regex so it can find if there is an @ sign within the string I'm searching.
import java.util.regex.*;
public class OnlineNewspaperSubscription extends NewspaperSubscription
{
public void setAddress(String a)
{
address = a;
// Creating a pattern from regex
Pattern pattern
= Pattern.compile("@*");
// Get the String to be matched
String stringToBeMatch = a;
// Create a matcher for the input String
Matcher matcher = pattern.matcher(stringToBeMatch);
if(matcher.matches())
{
super.rate = 9;
}
else
{
super.rate = 0;
System.out.println("Need an @ sign");
}
}
}
I should be able to tell whether this string is an email address or not.