我需要更换
\\\s+\\$\\$ to $$
Run Code Online (Sandbox Code Playgroud)
我用了
String s = " $$";
s = s.replaceAll("\\s+\\$\\$","$$");
Run Code Online (Sandbox Code Playgroud)
但它会抛出异常
java.lang.IllegalArgumentException:非法组引用
在匹配涉及美元符号的子模式时,我遇到了一些问题.例如,考虑以下文本块:
Regular Price: $20.50 Final Price: $15.20
Regular Price: $18.99 Final Price: $2.25
Regular Price: $11.22 Final Price: $33.44
Regular Price: $55.66 Final Price: $77.88
Run Code Online (Sandbox Code Playgroud)
我试图将常规/最终价格集与以下正则表达式匹配,但它根本不起作用(根本没有匹配):
preg_match_all("/Regular Price: \$(\d+\.\d{2}).*Final Price: \$(\d+\.\d{2})/U", $data, $matches);
我逃过了美元符号,所以给出了什么?