我尝试了这段代码。
DATA want;
PATTERN = PRXPARSE ("s/([cu])[o]([0-9a-z][0-9][0-9a-z])/$10$2/");
text="there was a co545 code in code c 0678";
RETAIN PATTERN;
CALL PRXCHANGE(PATTERN, -1, text);
run;
结果是"代码c 0678"中有545个代码。 如何更改代码以实现"代码c 0678中有c0545代码?我想要的是将字母o改为零(第二个字符)
答案 0 :(得分:1)
您需要做些什么来让它理解您想要$1
而不是$10
。来自这个网站:http://www.regular-expressions.info/replacebackref.html
Putting curly braces around the digit ${1} isolates the digit from any
literal digits that follow.
所以使用:
PATTERN = PRXPARSE ("s/([cu])[o]([0-9a-z][0-9][0-9a-z])/${1}0$2/");
答案 1 :(得分:0)
首先通过引入空间执行两个步骤,然后执行下一步以删除空间。
DATA want;
PATTERN = PRXPARSE ("s/([cu])[o]([0-9a-z][0-9][0-9a-z])/$1 0$2/");
PATTERN1 = PRXPARSE("s/([cu])\s([0-9a-z][0-9][0-9a-z]/$1$2/");
text="there was a co545 code in code c 0678";
RETAIN PATTERN;
RETAIN PATTERN1;
CALL PRXCHANGE(PATTERN, -1, text);
CALL PRXCHANGE(PATTERN1, -1, text);
run;