VEX Regex Captured Group Syntax
3372
4
0
AlanZ
Member
40 posts
Joined: Feb. 2018
Offline
Feb. 11, 2020 2:13 p.m.
I'm trying to do some regex stuff in VEX, but couldn't figure out how to use captured groups.
The
help page for re_replace() [
www.sidefx.com ] says that $1 syntax is used. I tried:
string foo = "H18" ;
s@bar = re_replace (r"H([0-9]+)" , "Houdini $1" , foo );
// desired result: 'Houdini 18'
// actual result: 'Houdini'
which ignores the ‘$1’. What am I doing wrong?
tamte
Member
9416 posts
Joined: July 2007
Offline
Feb. 11, 2020 2:23 p.m.
try this
string foo = "H18" ;
s@bar = re_replace (r"H([0-9]+)" , r"Houdini \1" , foo );
Tomas Slancik CG Supervisor Framestore, NY
AlanZ
Member
40 posts
Joined: Feb. 2018
Offline
Feb. 11, 2020 2:33 p.m.
tamte try thisstring foo = "H18" ;
s@bar = re_replace (r"H([0-9]+)" , r"Houdini \1" , foo );
That works perfect. Thank you so much!
ayoburgess
Member
37 posts
Joined: June 2008
Offline
Jan. 5, 2021 11:37 a.m.
tamte try thisstring foo = "H18" ;
s@bar = re_replace (r"H([0-9]+)" , r"Houdini \1" , foo );
This tip just saved me a bunch of time. Thank you. I'm curious how you figured this out, is this just something that's incorrect in the docs or is it explained somewhere else?
Thanks again
tamte
Member
9416 posts
Joined: July 2007
Offline
Jan. 7, 2021 11:41 a.m.
I think it's just standard regex way to use numbred backreference, not really unique to Houdini, so I guess it's just a typo in docs
Tomas Slancik CG Supervisor Framestore, NY