How to match the following sequence:
You wound DUMMY TARGET for 100 points of damage
but not:
You wound DUMMY TARGET with SKILL for 100 points of damage
with the regular expression:
^You wound ([\\w\\s]+)(?!with) for (\\d+) points of damage
The regular expression above is matching both strings while i expect to match only the first one. Is there any way to make this work?
Sample Java code:
import java.util.regex.*;
public class Dummy {
static Pattern pattern = Pattern.compile("^You wound ([\\w\\s]+)(?!with) for (\\d+) points of damage");
static Matcher matcher = pattern.matcher("");
static String FIRST_SEQUENCE = "You wound DUMMY TARGET for 100 points of damage";
static String SECOND_SEQUENCE = "You wound DUMMY TARGET with SKILL for 100 points of damage";
public static void main(String...args) {
if (matcher.reset(FIRST_SEQUENCE).matches())
System.out.println("First match. Ok!");
if (matcher.reset(SECOND_SEQUENCE).matches())
System.out.println("Second match. Wrong!");
}
}