String replacement in VEX

   14647   7   1
User Avatar
Member
96 posts
Joined: Nov. 2017
Offline
How do I replace a string with another string in VEX (e.g. change ../shop/.. to ../shopnet1/.. in the material path)?

Since there is no replace I tried to use re_replace. Not working unfortunately. What do I miss here? What kind of syntax is needed?

Cheers!
Tom
User Avatar
Member
8598 posts
Joined: July 2007
Offline
Tom Mangold
Not working unfortunately.
do you have specific not working example in mind?

as the straightforward case works:
string path = "../shop/principled1";
s@path = re_replace("../shop/", "../shopnet1/", path);

however if you want to be safe and really use correct regex you may need to do :
string path = "../shop/principled1";
s@path = re_replace(r"\.\./shop/", "../shopnet1/", path);

since otherwise . represents any character so it would match any 2 starting characters not just ..
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
59 posts
Joined: Nov. 2017
Offline
Thanks Tomas, that helped a lot!
User Avatar
Member
192 posts
Joined: April 2015
Offline
How would you do wildcards?

This isn't doing anything:

Thanks,
Edited by OdFotan - June 2, 2021 13:39:11

Attachments:
Screenshot 2021-06-02 at 19.37.39.png (10.7 KB)

User Avatar
Member
8598 posts
Joined: July 2007
Offline
For simple wildcards it's easier to use Attrib String Edit SOP (as with re_replace you have to use regex syntax)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
192 posts
Joined: April 2015
Offline
Looked for wildcard syntax in regex, but I don't really understand it or find the right answer. Do you know it? It's practically the only thing I need to know.

With the Attr String Edit SOP I have this problem that it operates on the updates values also. (Already submitted an RFE for an option to have an option to iterate on input values only)

See picture: In the end just everything is 'capBottom', 'capTop' is just dissapeared

Thats why I went into a wrangle, because there I could write it unto a temporary attribute.

-
Edited by OdFotan - June 4, 2021 11:22:27

Attachments:
Screenshot 2021-06-02 at 19.19.45.png (35.6 KB)

User Avatar
Member
8598 posts
Joined: July 2007
Offline
OdFotan
How would you do wildcards?

This isn't doing anything:
Image Not Found

Thanks,
for such simple case of direct replacement you can omit pattern matching and do this directly
s@opposite_name = re_replace("capTop", "capBottom", s@name);
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
192 posts
Joined: April 2015
Offline
Thank you,
It works.

I guess this is no 'syntax' at all,
  • Quick Links