I am working on some socket programming stuff and attempting to match some strings. The format is as follows:
1.) Some text
where the one represents any number, and some text refers to anything (including letters, numbers, quotation marks, etc).
I tried using [0-9]*\\.\\).* but it doesn’t return a match. What am I doing wrong and how do I fix it?
Edit
As requested, here is my code:
/** Parses data returned by the server */
public void getSocketData(String data) {
String[] lines = data.split("\\r?\\n");
this.fileHosts = new String[lines.length];
Pattern p = Pattern.compile("[0-9]*\\.\\).*");
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (p.matcher(line).matches()) {
//The format is: 1.) "b.jpg" from "192.168.1.101:40000"
String[] info = line.split("\"");
this.fileHosts[i] = info[3]; //this should now contain <addr:port>
System.out.println("Adding " + fileHosts[i] + " to fileHosts");
}
else {
System.out.println("No Match!");
}
}
}//getSocketData
This works for me:
Output:
EDIT: Same result with the following:
That is the example in the comment in your code
EDIT2: I try also your code:
The result is
Try using this regex:
^[0-9]+\\.\\).*$