Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.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_Matlab - Fatal编程技术网

Regex 替换括号内的字符

Regex 替换括号内的字符,regex,matlab,Regex,Matlab,我试图想出一个正则表达式,它可以用空格分隔括号内的所有破折号。我提出了以下建议: regexprep(input, '(\w| +)-(\w+)(?=.*\))', '$1 - $2'); 但是,当运行字符串(this-is-a-biger-test)时,我得到的结果是(this-is-a-biger-test),而不是预期的(this-is-a-biger-test) 我在这个正则表达式的分组中缺少了什么?我想这正是您想要的: str_out = regexprep(str_in, '(

我试图想出一个正则表达式,它可以用空格分隔括号内的所有破折号。我提出了以下建议:

regexprep(input, '(\w| +)-(\w+)(?=.*\))', '$1 - $2');  
但是,当运行字符串
(this-is-a-biger-test)
时,我得到的结果是
(this-is-a-biger-test)
,而不是预期的
(this-is-a-biger-test)


我在这个正则表达式的分组中缺少了什么?

我想这正是您想要的:

str_out = regexprep(str_in, '(?<=\(.*)-(?=.*\))', ' - ');

在一个“(这是一个更大的测试)”的情况下,正则表达式需要更新:
(?@stribizhev考虑得很好!但是对于
”(这是一个更大的测试)
(在
更大之前使用双空格)它会将双空格变成一个空格。不确定这是OP想要的。感谢@stribzhev的建议(感谢OP提供的原始答案)。这就解决了我的问题。你知道正则表达式引擎matlab使用什么吗?@sln除了偶尔在matlab中使用外,我对正则表达式知之甚少。也许有帮助。你知道它是否在括号之间吗?
str_out = regexprep(str_in, '(?<=\(.*)\s*-\s*(?=.*\))', ' - ');