如何从字符串中替换这个:“/”。
例如:"one/another one“-> "one / another one”
它只是删除斜杠之间的空格..不是空格。
谢谢。
发布于 2020-06-30 19:07:16
此正则表达式将去掉斜杠周围的所有空格,但保持斜杠不变。
> "one / another one / yet some more / until the end".replace(/\s*\/\s*/g, '/')
"one/another one/yet some more/until the end"
例如,如果您需要保持////
完好无损,请使用+
作为量词:
> "one / another one / yet some more / until the end (yet this //// remains)".replace(/\s+\/\s+/g, '/')
"one/another one/yet some more/until the end (yet this //// remains)"
发布于 2020-06-30 19:09:55
您可以这样做:
console.log("one / another one".replace(/\ \/ /, '/'));
发布于 2020-06-30 19:12:25
您没有指定语言;在我的回答中,我将使用Python;使用- string_name = string_name.replace(' / ','/')
(其中string_name是存储实际字符串的变量的名称)
这里使用' replace ()‘,在第一个参数中提供要替换的内容,在第二个参数中提供要替换的内容
https://stackoverflow.com/questions/62656044
复制相似问题