you need to set the compiler to c++ 17 or higher in the project settings.
string view is good performance, read this:
https://www.nextptr.com/tutorial/ta1217154594/cplusplus-stdstring_view-for-better-performance-an-example-use-case
I can think of several ways to do this problem.
c++ has built in regular expressions, and I believe that is what you have here. Basically x followed by 1 or more y followed by q followed by one of d or z followed by x followed by 1 or more y... you can express that in regex and just let the library do the work.
it is also a finite state machine. this is a convoluted way to code it.
straight iteration is probably the most efficient, just touching each letter one time and failing if it goes wrong else passing at the end. This is a lot like what you have, but just lump it all up, don't try to make extra functions.
you can use string replace to simplify it. if you replace all yy with y until only single ys remain, there are I think 5 or 6 possible results, which you can then check in a lookup table and its done {xy, xyqd, xyqz, xyqdxy, xyqzxy, is that all of them?}
and there are plenty more snarky things to do with the 3 string libraries and c++ tools. But nothing will ever be more efficient than touching each letter one time and pass/fail. Clever, short and clean code can be a nightmare of inefficiency behind the scene ... the tools and libraries hide tons of loops and copies and such if you are not very careful about it. And it does not matter, if you are playing, but its an important thing if you need speed.