Finding “\n” characters using re_find() in VEX

   3031   3   2
User Avatar
Member
192 posts
Joined: April 2015
Offline
Hi peoples,

was hoping anyone could help me figure out how to find the ‘/n’ in a string? It's just in the string attribute I am looping over as characters, and any other character it will find with re_find, but not these. I searched and tried a lot but did not succeed.

Thanks in advance.
Edited by OdFotan - April 29, 2020 13:14:02
User Avatar
Member
192 posts
Joined: April 2015
Offline
I'll post a hip file because I actually saw that a \n makes this little symbol when the string is made with a Attribute Create SOP.

With the method I had it didn't and existed just as characters.


Here is the hip file:
Edited by OdFotan - April 29, 2020 14:55:20

Attachments:
Screenshot 2020-04-29 at 20.51.15.png (7.3 KB)
Screenshot 2020-04-29 at 20.51.27.png (20.3 KB)
find newline characters.hipnc (262.9 KB)

User Avatar
Member
325 posts
Joined: Jan. 2013
Offline
I suppose that this could be done. The newline character needs to be escaped.

string strings = "this is a string array and \n this is a new line";
s[]@words = re_split(r'( +)|(\\n)', strings);

// Result: [ this, is, a, string, array, and, "", "", this, is, a, new, line ]
User Avatar
Member
192 posts
Joined: April 2015
Offline
I did try some stuff with that r’()’ before, even tho I do not understand it fully.
But this code also doesn’t work in this hip file:


Also: I read that ‘regex’ is mostly the same, but that still different languages use different regex engines with small variations.
If you want to learn regex for vex, is there a specific 'regex engine’ you should focus on?
Edited by OdFotan - April 30, 2020 04:27:23

Attachments:
ScreenFlow.gif (2.3 MB)

  • Quick Links