Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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 如何使用正则表达式查找和替换新的rxjs语法?_Regex_Visual Studio Code_Rxjs_Find Replace - Fatal编程技术网

Regex 如何使用正则表达式查找和替换新的rxjs语法?

Regex 如何使用正则表达式查找和替换新的rxjs语法?,regex,visual-studio-code,rxjs,find-replace,Regex,Visual Studio Code,Rxjs,Find Replace,我想将我的rxjs代码升级到新语法。为此,我使用vscode和regex“查找并替换” 旧语法: .pipe( catchError((err) => { ... }) ) .subscribe((res) => { ... }); 新语法是: .subscribe({ next: (res) => { ... }, error: (err) => { ... }); 我尝试使用我构建的这个正则表达式,但我似乎觉得正则表达式是错误的,不知道为什

我想将我的rxjs代码升级到新语法。为此,我使用vscode和regex“查找并替换”

旧语法:

.pipe(
 catchError((err) => {
   ...
 })
 )
 .subscribe((res) => {
   ...
 });
新语法是:

 .subscribe({ next: (res) => { ... }, error: (err) => { ... });
我尝试使用我构建的这个正则表达式,但我似乎觉得正则表达式是错误的,不知道为什么,因为在这个正则表达式中,我找到了
catchError
subscribe
之间的区别。那么,如何让它以正确的方式工作呢

\.pipe(\s\ScatchError(.*).subscribe(.*)
另外,我如何将匹配此模式的所有地方替换为新模式? 您可以使用

^\.pipe\(\n\s*catchError([\w\w]*?\}\)\n\s*\)\s*\.subscribe([\w\w]*?\}\)$

详细信息

  • ^
    -行的开头
  • \.pipe\(
    -文本
    .pipe(
    文本
  • \n
    -换行符
  • \s*
    -0+空格
  • catchError
    -文字
  • ([\w\w]*?\}\)
    -第1组:任何零个或多个字符,尽可能少,直到并包括
    })
    子字符串
  • \n\s*
    -换行符和0+空格
  • \)
    -a
    字符
  • \s*
    -0+空格
  • \.subscribe
    -文本
    .subscribe
    字符串
  • ([\w\w]*?\}\)
    -第2组:任何零个或多个字符,尽可能少,直到并包括
    })
    子字符串
  • $-a
    行末尾的字符

您确定可以用整个代码库中的第二部分替换第一部分而不会导致错误吗?考虑流在<代码> CasChrror < /C>中返回的情况,并且<<代码> NeX/<代码>回调在<代码>订阅< /代码>中应该处理来自该流的值。可以观察到,旧语法中的错误将同时执行
catchError
subscribe next
中的代码,而在新语法中,只执行
subscribe error
部分。因此,在每种情况下,如果不涉及代码,就不能将第一个替换为第二个。我有许多文件具有相同的模式
.pipe…catchError…subscribe
。我只想对这些模式做些修改。但只能是
\n
和它们之间的空格。请尝试
^\.pipe\(\n\s*catchError([\w\w]*?\}\)\n[\w\w]*?\.subscribe([\w\w]*?\}\)$()。或者有点。酷。它们之间的区别是什么?第一个包含了<>代码> [\W\W]*<代码>中间,这可能在多个<代码> >管道< /代码> s中过度匹配。