public class OneTimeAtLeast
{
public static void main(String[] args)
{
String str = "12*/34";
Matcher m = Pattern.compile("[\\+-\\*/]").matcher(str);
if (m.find())
System.out.println(m.start());
else
System.out.println("没有匹配到!");
}
}
可是用斜杠 / 而不是反斜杠 \ 来转意却能运行成功
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class OneTimeAtLeast
{
public static void main(String[] args)
{
String str = "12*/34";
Matcher m = Pattern.compile("[/+-/*/]").matcher(str);
if (m.find())
System.out.println(m.start());
else
System.out.println("没有匹配到!");
}
}