此问题在此处已有答案:
How to replace a number in a URL using JavaScript(3个答案)
Regexp: replace all digits on URL after third slash(1个答案)
昨天关门了。
我有一个像https://test.com/id/3/5000/333
这样的文本字符串,我想用任意数字替换最后一个数字5000
和3000
。如何在javascript中使用正则表达式?谢谢
此问题在此处已有答案:
How to replace a number in a URL using JavaScript(3个答案)
Regexp: replace all digits on URL after third slash(1个答案)
昨天关门了。
我有一个像https://test.com/id/3/5000/333
这样的文本字符串,我想用任意数字替换最后一个数字5000
和3000
。如何在javascript中使用正则表达式?谢谢
2条答案
按热度按时间zbwhf8kr1#
您可以使用
\d+/\d+$
来匹配两组连续的数字,这两组数字在字符串结尾之前用斜杠分隔。6tqwzwtp2#
如果您有queryParams,您可以尝试从原始URL字符串构造一个
URL
对象并操作pathname
。