0

I have executed the code below, but its result is false. Is my pattern is correct? What is wrong here? If I am wrong please correct me because I am stuck on this.

String name = "] RESPONSE GET - 192.168.200.121 -";
string pat = "] RESPONSE (GET|GETNEXT|GETBULK|SET|TRAP) - ^192\\.168\\.200\\.121$ -";
Pattern p = Pattern.compile(pat);
Matcher m = p.matcher(name);
System.out.println(m.find());
4

1 回答 1

3

这有效:

] RESPONSE (GET|GETNEXT|GETBULK|SET|TRAP) - 192\\.168\\.200\\.121 -

您的字符串中间有^and$字符。它们分别代表要匹配的字符串的开始和结束。显然,字符串的开头/结尾不能在字符串的中间;-)

于 2013-01-07T14:57:07.070 回答