RFE: Regex escape VEX method

   6172   6   0
User Avatar
Member
5238 posts
Joined: Feb. 2012
Offline
It would save a lot of time and frustration if we had an escape method for VEX regex methods. To get the number at the end of a string for example you have to use this:

string num = re_find("(\d+)$", s);

but you have to escape it:

string num = re_find("(\\\\\d+)$", s);

The internet is full of useful regex examples that could save you a lot of time but good luck using them in Houdini as is.

Languages like Python and C# have intuitive ways to escape regular expressions.

ID# 68317 - Submitted more than a year ago.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Staff
2686 posts
Joined: July 2005
Offline
In H15.5, VEX now supports C++11 style raw strings.
string num = re_find(R"((\d+)$)", s);
User Avatar
Member
5238 posts
Joined: Feb. 2012
Offline
Thanks Mark, this is great news. I will use it a lot for sure.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
9651 posts
Joined: July 2007
Offline
this should work for h14.0 and 15.0:
string num = re_find(r"(\d+)$", s);
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
5238 posts
Joined: Feb. 2012
Offline
tamte
this should work for h14.0 and 15.0:
string num = re_find(r"(\d+)$", s);

Thanks for showing this. Is this documented? I never come across it before in VEX.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Staff
2686 posts
Joined: July 2005
Offline
GAK! I jumped the gun. Sorry, C++11 raw strings are only in the HEAD version of Houdini, not 15.5… So, it's coming.

Very sorry to raise hopes.

In the meantime, you can use the Python style raw strings (thanks for fixing me tamte).

They are documented: http://archive.sidefx.com/docs/houdini15.5/vex/strings [archive.sidefx.com]
User Avatar
Member
5238 posts
Joined: Feb. 2012
Offline
Thanks for clearing that up Mark. Very useful.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
  • Quick Links