regex - SAS replacing a specific pattern without space back in the text -
for eg text this- "i have these codes c 6780, u 6780, c0555". output giving is- "i have these codes ([cu][0-9o][0-9a-z]{3}), ([cu][0-9o][0-9a-z]{3}), c0545". expecting "i have these codes c6780, u6780, c0555". tried code.
data replace_pat; set text; if _n_ =1 pattern = prxparse ("s/([cu]\s[0-9o][0-9a-z]{3})/([cu][0-9o][0-9a-z]{3})/"); retain pattern; call prxchange(pattern, -1, text); run; how change code achieve this?
you need enclose bits want keep in parens (not whole thing) create capture groups, refer capture groups using $1 $2.
data replace_pat; set text; if _n_ =1 pattern = prxparse ("s/([cu])\s([0-9o][0-9a-z]{3})/$1$2/"); retain pattern; call prxchange(pattern, -1, text); run; you might want o option after final / avoid having silly if n = 1 bit.
Comments
Post a Comment