Simple regular expression:
Pattern p = Pattern.compile("(0)\\s(HEAD)"); Matcher m = p.matcher("0 HEAD"); String d=""; if (m.find()) { d=m.group(2); } if (d=="HEAD") { d="OK"; } But, unfortunately, d! = "HEAD". Where is the mistake?
Simple regular expression:
Pattern p = Pattern.compile("(0)\\s(HEAD)"); Matcher m = p.matcher("0 HEAD"); String d=""; if (m.find()) { d=m.group(2); } if (d=="HEAD") { d="OK"; } But, unfortunately, d! = "HEAD". Where is the mistake?
In Java, strings are objects and need to be compared using .equals . In your case, the condition should be as follows:
if (d.equals("HEAD")) { d = "OK"; } Source: https://ru.stackoverflow.com/questions/246341/
All Articles