< 强 > 注意: 我正 - 不试图用正gex 强 > 分析 HTML
我试图在字符串中替换任何用美元符号(例如美元)包裹的内容。 我设法找到str.replace (/$([ $]*]$/g), "Hello $1!")
, 但我有问题要保证在用 HTML 标记包裹时不会替换这些字符串 。
示例字符串: $ someone$, & lt; a> $welcome$</ a> 和 $another$
表达式: /[gt;]$([ $] *)$[lt;]/g
预期输出 : hello someone!, & lt; a> $welcome</ a>, 并再次向您问好! code>
实际产出: $ somesonhello, $7.elcomhello, $2. other$
测试代码 : alert ($ someone$,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
fiddle: http://jsfiddle.net/WMWHZ/
谢谢!