我想在一个字符串中识别两种类型的模式。它们是:
1) xxx:xxxxxxx:xxx.xx
2) xxx.xxx.xxx.xx:xxxxxxxxxx
基本上,我想知道如何识别字符串中的文字"."
。
由于.
表示任何字符,因此在查找文字"."
时应该键入什么
发布于 2013-05-17 23:51:10
您可以像下面的\\.
一样转义.
或
在字符类中使用它,如下所示的[.]
发布于 2013-05-17 23:56:28
尝试使用,String [] stringArray = string.split("\\.");
转义“。
然后是int periods = stringArray.length;
告诉你在你的字符串中有多少句点
这只是转义字符的一个开始。我不确定你的问题是什么,所以我只是给出了一个逃脱的介绍。
发布于 2013-05-18 00:05:02
祝好运
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);
}
https://stackoverflow.com/questions/16613231
复制相似问题