【问题标题】:Replace parentheses in URL strings [duplicate]替换 URL 字符串中的括号 [重复]
【发布时间】:2013-08-22 06:00:40
【问题描述】:

我有如下 URL 链接的字符串。但是当 url 有如下括号时,url 就会中断。 url 在 URL 中括号的开头被打破。

This is test http://ang.wikipedia.org/wiki/Wikipedia:Tutorial_(Wikipedia_links) 

我们可以使用 javascript 正则表达式将括号替换为其他 ASCII 字符吗?

【问题讨论】:

  • 你可以使用url编码吗?
  • 查看之前的 SO 帖子:stackoverflow.com/questions/332872/… 如果您遇到编码问题,我假设您这样做了,这可以以更强大的方式完成工作。跨度>

标签: javascript regex urlencode


【解决方案1】:

使用string.replace() 方法。

url = url.replace(/\(/g, '%28').replace(/\)/g, '%29');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-01
    • 2018-12-26
    • 2015-04-16
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 2014-03-09
    • 2021-07-06
    相关资源
    最近更新 更多