掩码 @ SAS RegEX 中的字符



我的正则表达式 s/<<[\w|+|@|#]+>>/\s*(<<[\w|\+|#|@]+>>)\s*/的替换字符串中的@字符(粗体)导致错误。当我将正则表达式替换为 s/<<[\w|+|@|#]+>>/\s*(<<[\w|\+|#]+>>)\s*/时,错误消失了。

如何屏蔽@字符。%NRSTR似乎不起作用。

法典:

Data _NULL_;
a=prxchange(%NRSTR("s/<<[w|+|@|#]+>>/s*(<<[\w|\+|#|@]+>>)s*/"), -1, "<<A>> <<A+>> <<A@>> <<A@+>> <<A#>> <<A#+>>");
putlog a;
run;

.LOG:

ERROR: An array reference was found in replacement text
"s/<<[w|+|@|#]+>>/s*(<<[\w|\+|#|@]+>>)s*/". Array references within replacement text
are not supported.
ERROR: The regular expression passed to the function PRXCHANGE contains a syntax error.
NOTE: Argument 1 to function PRXCHANGE('s/<<[w|+|@'[12 of 46 characters shown],-1,'<<WORD>>
<<W'[12 of 60 characters shown]) at line 1656 column 3 is invalid.

a=  _ERROR_=1 _N_=1

这是你想要的吗? 我在 & 符号之前添加了转义字符。

data _null_;
length regex in out $200 ;
regex='s/<<[w|+|@|#]+>>/s*(<<[\w|\+|#|@]+>>)s*/';
in = '<<A>> <<A+>> <<A@>> <<A@+>> <<A#>> <<A#+>>';
out=prxchange(regex,-1,in);
putlog (_all_) (//= :$quote.);
run;

结果:

regex="s/<<[w|+|@|#]+>>/s*(<<[\w|\+|#|@]+>>)s*/"
in="<<A>> <<A+>> <<A@>> <<A@+>> <<A#>> <<A#+>>"
out="s*(<<[w|+|#|@]+>>)s* s*(<<[w|+|#|@]+>>)s* s*(<<[w|+|#|@]+>>)s* s*(<<[w|+|#|@]+>>)s* s*(<<[w|
+|#|@]+>>)s* s*(<<[w|+|#|@]+>>)s*"

最新更新