Hi,
I am learning to use regular expressions, and I am curious about the approach to take when trying to exclude a specific portion of text in a string with regexm.
A simplification of my problem: I have a variable called rainbow, which can be: "pinkyellow redyellow yellowgreen yellow purple" and I want to generate a variable colours = 1 when rainbow contains yellow but not red.
I can achieve this with strops as follows: replace colours= 1 if strpos(rainbow,"yellow") > 0 & strpos(rainbow,"red") == 0
how can I achieve the same result with regexm? that is, how do you exclude a specific string such as "red" using regexm?
Thanks a lot!
I am learning to use regular expressions, and I am curious about the approach to take when trying to exclude a specific portion of text in a string with regexm.
A simplification of my problem: I have a variable called rainbow, which can be: "pinkyellow redyellow yellowgreen yellow purple" and I want to generate a variable colours = 1 when rainbow contains yellow but not red.
I can achieve this with strops as follows: replace colours= 1 if strpos(rainbow,"yellow") > 0 & strpos(rainbow,"red") == 0
how can I achieve the same result with regexm? that is, how do you exclude a specific string such as "red" using regexm?
Thanks a lot!
Comment