2013-05-17 209 views
1

我想确定字符串中的两种模式。它们是:正则表达式Java(标点符号)

1)xxx:xxxxxxx:xxx.xx

2)xxx.xxx.xxx.xx:xxxxxxxxxx

基本上我想知道如何在一个字符串识别文字"."

由于.表示任何字符,当我正在寻找文字"."时应该键入什么?

+1

使用java模式,并与\\匹配器。 [source] [1] [1]:http://stackoverflow.com/questions/3674930/java-regex-meta-character-and-ordinary-dot –

回答

10

您可以逃脱.这样\\.

字符类中使用这样的[.]

0

尝试使用,String [] stringArray = string.split("\\."); 逃脱 “”

然后int periods = stringArray.length;

告诉你有多少时间有你的“字符串”

上逃脱字符只是一个开始。我不确定你的问题在问什么,所以我只是给了一个介绍来逃避。

0

好运

String text ="xxx.xxx.xxx.xx:xxxxxxxxxx"; 

    String patternString = "(.*)(\\.)(.*)"; 

    Pattern pattern = Pattern.compile(patternString); 

    Matcher matcher = pattern.matcher(text); 
    boolean matches = matcher.matches(); 
    System.out.println(matches); 
} 
相关问题