
poly4life
Novice
Mar 25, 2011, 9:30 AM
Post #1 of 4
(1240 views)
|
|
Is there a way to use qq() or q() with replacement in regex?
|
Can't Post
|
|
Hello, I hope my logic makes sense, here. I have a regex: s~pattern~replacement~g If I have to escape quotes or apostrophes, I'd normally do this: s~foo~\'foo\'~g or s~foo~\"foo\"~g This can become unpleasant looking with multiple escapes: s~foo~\'foo\'\'bar\'\"foo\"\"bar\"~g Is there some means where I can use something similar to qq(...) or q(...) to automatically escape the quotes and apostrophes? If you look at extended pattern modfiers like (?s) or /Q.../E, you can essentially enclose the pattern. I've never used something like /Q.../E for replacement, so I don't know if you can apply those modifiers to the replacement string. But I didn't see a modifier for quotes or apostrophes. Essentially, I want the regex expression to look like this: s~foo~qq(bar)q(bar)~g, which would be equivalent to s~foo~\"bar\"\'bar\'~g. I would appreciate any help. Thank you.
|