VEX Regex Captured Group Syntax

   3372   4   0
User Avatar
Member
40 posts
Joined: Feb. 2018
Offline
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?
User Avatar
Member
9416 posts
Joined: July 2007
Offline
try this
string foo = "H18";
s@bar = re_replace(r"H([0-9]+)", r"Houdini \1", foo);
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
40 posts
Joined: Feb. 2018
Offline
tamte
try this
string foo = "H18";
s@bar = re_replace(r"H([0-9]+)", r"Houdini \1", foo);


That works perfect. Thank you so much!
User Avatar
Member
37 posts
Joined: June 2008
Offline
tamte
try this
string 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
User Avatar
Member
9416 posts
Joined: July 2007
Offline
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
  • Quick Links