Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.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
使用regexprep向前看和向后看断言_Regex_Matlab - Fatal编程技术网

使用regexprep向前看和向后看断言

使用regexprep向前看和向后看断言,regex,matlab,Regex,Matlab,以下操作与perl的s///g字符串替换运算符的预期操作相同: DB<18> $s = 'camelCaseText.ext' DB<19> $s =~ s/\W|(?<=[^\WA-Z_])(?=[A-Z])/\$/g; print $s camel$Case$Text$ext DB$s='camelCaseText.ext' DB$s=~s/\W |(?>regexprep('camelCaseText.ext','\W |)(?我认为您需要指定emp

以下操作与
perl
s///g
字符串替换运算符的预期操作相同:

  DB<18> $s = 'camelCaseText.ext'
  DB<19> $s =~ s/\W|(?<=[^\WA-Z_])(?=[A-Z])/\$/g; print $s
camel$Case$Text$ext
DB$s='camelCaseText.ext'

DB$s=~s/\W |(?>regexprep('camelCaseText.ext','\W |)(?我认为您需要指定
emptymatch
选项。根据,默认情况下它忽略零长度匹配

>> regexprep('camelCaseText.ext', '\W|(?<=[^\WA-Z_])(?=[A-Z])', '$', 'emptymatch')

>regexprep('camelCaseText.ext','\W |)(?我不知道!我试图让代码更可读,但这有点违背了目的。我将其压缩为一行。感谢大家的提醒。
>> regexprep('camelCaseText.ext', '\W|(?<=[^\WA-Z_])(?=[A-Z])', '$', 'emptymatch')