import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=\\s)#\\w+(?!.*[@$#])";
final String string = "1. While #EngineSpeed$b4tgup#\n"
+ "2. While #AcceleratorPedal$desddd# <=2\n"
+ "3. While #AcceleratorPeda@$desddd# <=2\n"
+ "4. While #AcceleratorPe#al$desddd# <=2\n"
+ "5. While #AcceleratorP@dal$desddd# <=2\n"
+ "6. While #AcceleratorPeda l$desddd# <=2\n"
+ "7. 设置 #AcceleratorPedal$y6qs8m#=@AcceleratorPedal+0.06\n"
+ "8. 设置 #WaitStart$jhx0vu#=11\n"
+ "9. 设置 #WaitStart$jhx0vu#^11\n"
+ "10. 设置 #WaitStart$jhx0vu#_11\n"
+ "11. 设置 #WaitStart$jhx0vu#-11\n"
+ "12. 设置 #AcceleratorQuora$yd6ba3#=1\n"
+ "13. 设置 #AcceleratorQuora$yd6bd3#=1\n"
+ "14.\n"
+ "15. Check #EnginePower#\n"
+ "16. While #EngineSpeed\n"
+ "17. set #WaitStart\n"
+ "18. set #WaitStart<13\n"
+ "19. set #WaitStart<=13\n"
+ "20. set #WaitStart <= 13";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html