Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正则表达式替换方括号之间的字符,但不替换括号之间的字符_Regex_Sublimetext3_Regex Lookarounds - Fatal编程技术网

Regex 正则表达式替换方括号之间的字符,但不替换括号之间的字符

Regex 正则表达式替换方括号之间的字符,但不替换括号之间的字符,regex,sublimetext3,regex-lookarounds,Regex,Sublimetext3,Regex Lookarounds,我有一个降价链接列表,如下所示: [filename-with-some-words](/001-folder/filename-with-some-words.md) [title-with-other-words](/001-folder/title-with-other-words.md) [other-words](/001-folder/other-words.md) 我想替换方括号中出现的-,[],而不是括号中出现的(),这样我的最终结果如下所示: [filename with s

我有一个降价链接列表,如下所示:

[filename-with-some-words](/001-folder/filename-with-some-words.md)
[title-with-other-words](/001-folder/title-with-other-words.md)
[other-words](/001-folder/other-words.md)
我想替换方括号中出现的
-
[]
,而不是括号中出现的
()
,这样我的最终结果如下所示:

[filename with some words](/001-folder/filename-with-some-words.md)
[title with other words](/001-folder/title-with-other-words.md)
[other words](/001-folder/other-words.md)
我可以用
(?您可以使用

(?:\G(?!\A)|\[)[^][-]*\K-(?=[^][]*])
替换为空格。请参见

详细信息

  • (?:\G(?!\A)\[)
    -上一次成功匹配的结束或
    [
  • [^][-]*
    -除
    ]
    [
    -
    以外的任何0+字符
  • \K
    -匹配重置操作符丢弃所有匹配的文本,直到整个匹配内存缓冲区
  • -
    -连字符
  • (?=[^][]*])
    -后面跟0+个无括号字符,直到
    ]
    字符