需要帮助更改多个 HTML 页面上的价格,使用正则表达式 dreamweaver,想要将价格乘以 4
我的任务很简单。我想替换所有以价值乘以 4 标记的价格(在 HTML 页面上)。
因此 500 美元应该变成 2000 美元。代码是什么?
然后我想要更大的价格,比如 5000 美元,只需乘以 2 代码是什么?
My task is simple. I want to replace all the prices (on HTML pages) marked by their value multiplied by 4.
So $500 should become $2000. What would the code be for that?
Then I would like bigger prices, like $5000, to only be multiplied by 2
What would be the code for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不能通过简单的正则表达式替换来完成。请注意,正则表达式模式不匹配数字(可以使用 +、- 等进行操作),但它匹配字符串。
唯一的可能性是将
\$5000
替换为\$10000
($
是一个特殊字符,需要转义)。我意识到,对于许多不同的金额,这对您来说不是一个可行的解决方案。但是,如果您只有少量不同的金额,则可以进行几次此类替换(注意不要替换金额两次!)。That can't be done by a simple regex-replacement. Realize that a regex pattern does not match numbers (which can be operated on with +, -, etc.), but it matches strings.
The only possibility would be to replace
\$5000
with\$10000
(the$
is a special char and needs to be escaped). I realize that with many different amounts, this is not a viable solution for you. However, if you have just a handful of different amount, you could do a couple of such replacements (be careful not to replace amounts twice!).您需要的是像 BeautifulSoup 这样了解 HTML 结构的东西。
What you need is something like BeautifulSoup that knows about the structure of HTML.