0

複数の式と置換に matlab regexprep を使用する方法は?

file='http:xxx/sys/tags/Rel/total';

「sys」を「sys1」に、「total」を「total1」に置き換えたいと思います。単一の式の置換の場合、次のように機能します。

strrep(file,'sys', 'sys1')

そして好きになりたい

strrep(file,'sys','sys1','total','total1') . 

私はこれがうまくいかないことを知っていますstrrep

4

3 に答える 3

0

To solve it you need substitute functionality with regex, try to find in matlab's regexes something similar to this in php:

$string = 'http:xxx/sys/tags/Rel/total';
preg_replace('/http:(.*?)\//', 'http:${1}1/', $string);  

${1} means 1st match group, that is what in parenthesis, (.*?).

http:(.*?)\/ - match pattern

http:${1}1/ - replace pattern with second 1 as you wish to add (first 1 is a group number)

http:xxx/sys/tags/Rel/total - input string

The secret is that whatever is matched by (.*?) (whether xxx or yyyy or 1234) will be inserted instead of ${1} in replace pattern, and then replace instead of old stuff into the input string. Welcome to see more examples on substitute functionality in php.

于 2012-11-01T13:22:56.110 に答える
0

コマンドを 2 回発行しないのはなぜですか?

file = 'http:xxx/sys/tags/Rel/total';

file = strrep(file,'sys','sys1')
strrep(file,'total','total1')
于 2012-11-01T12:40:20.697 に答える