I have a CMake string variable:
set(var "String0 String_1 String_2")
I need to select whatever is before the first whitespace from this variable ("String0") and make a new variable with this content.
I used CMake's REGEX MATCH method to do this and used this regex: '\S\w*'. I have tested that regex on an online regex interpreter and it worked.
I have written this code in CMake (after setting the variable of course):
string(REGEX MATCH "\S\w*" NEW_VAR "${VAR}")
When I do this the script complains about invalid skipping of characters (S and w). So, next, I tried escaping both the slashes:
string(REGEX MATCH "\\S\\w*" NEW_VAR "${VAR}")
Now NEW_VAR equal 'S' instead of "String0" as I was expecting.
Please help me correct this, since I have very little experience with regular expressions and CMake.
\Sand\w.Editparagrapgh into the answer post.