1

I would like to identify 2 types of patterns in a string. They are:

1) xxx:xxxxxxx:xxx.xx

2) xxx.xxx.xxx.xx:xxxxxxxxxx

Basically I want to know how to identify a literal "." in a string.

Since . means any character, what should I type when I am looking for a literal "."?

ajp15243
  • 7,704
  • 1
  • 32
  • 38
user1769197
  • 2,132
  • 5
  • 18
  • 32
  • 1
    use the java Pattern and Matcher with \\. [source][1] [1]: http://stackoverflow.com/questions/3674930/java-regex-meta-character-and-ordinary-dot – grepit May 17 '13 at 15:53

3 Answers3

10

You can either escape the . like this \\.

or

use it within character class like this [.]

Anirudha
  • 32,393
  • 7
  • 68
  • 89
0

Try using, String [] stringArray = string.split("\\."); escaping the "."

And then int periods = stringArray.length;

Telling you how many periods there are in your "String"

Just a start on escaping characters. I am unsure what your question is asking so I just gave an intro to escaping.

Dummy Code
  • 1,858
  • 4
  • 19
  • 38
0

good luck

    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);
}
grepit
  • 21,260
  • 6
  • 105
  • 81