RegEx替换字符串中的@
字符(粗体)s / << [\ w | + | @ |#] + >> / \ s *(<< [\ w | \ + |# | @ ] + >>)\ s * /导致错误。当我用s / << [\ w | + | @ |#] + >> / \ s *(<< [\ w | \ + |#] + >>)\ s * /替换RegEx时,错误消失了。
如何屏蔽@
字符。 %NRSTR
似乎无效。
代码:
Data _NULL_;
a=prxchange(%NRSTR("s/<<[\w|\+|@|#]+>>/\s*(<<[\\w|\\+|#|@]+>>)\s*/"), -1, "<<A>> <<A+>> <<A@>> <<A@+>> <<A#>> <<A#+>>");
putlog a;
run;
日志:
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
答案 0 :(得分:0)
这是您想要的吗?我在&符之前添加了转义符。
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*"