You'll want to use regex to parse that string, which is handily available in QGIS as the function regex_substr()
.
Assuming your name always follows the project number in the format you've given (i.e. separated by a space, -, and another space), you can try the following expression:
regexp_substr(@project_folder,
'^(?:[^\\\\]+\\\\){8}([^\\\\]+)(?:\\\\)') || ' / ' ||
regexp_substr(@project_folder,
'^(?:[^\\\\]+\\\\){9}(?:\\w+ - )([^\\\\]+)')
The first part extracts the client name. The bit up to and including the number with the curly brackets looks for:
This is then concatenated with a forward slash and spaces (|| ' / ' ||
)
Followed by the project name, which is much like the above, except it looks for
- 9 instances of anything + backslash
- followed by another non-capturing group of
- any non-whitespace characters
- followed by a space, - symbol, and space
- which is your project number:
(?:\\w+ - )
- and then, again, anything but a backslash any number of times (
[^\\\\]
)
- this is your project name.
Note that backslashes are escaped in normal expression editing in QGIS by doubling them up, and use of regex functions requires the same, so to convey the backslash character in regexp_substr()
and similar functions, backslashes must be typed as \\\\