Q1.I want to match “&JOY” in a user input string, for example, “bla bla &JOY bla bla &JOY blabla”
How can I write the regex expression for this, and are there any C regex functions could return all the positions where the matches happen?
Q2.If I want to substitute &JOY with another string is there a convenient C function to do this?
Q1.I want to match &JOY in a user input string, for example, bla bla
Share
C standard library does not provide regex functions. However, as your example looks for a fixed string, you don’t need regex. Substring search is enough. It can be accomplished with strstr function:
As to your second question — no, there is no such function. You have to do it manually: