Question: Is there a worksaround for this oddity in RegMatch and RegSubs?


 

with(StringTools)

s := "xABCx etc"; RegMatch("x(.+)x", s, 'm', 'n'); m; n; RegSubs(m = n, s)

"xABCx etc"

 

true

 

"xABCx"

 

"ABC"

 

"ABC etc"

(1)

s := "(ABC) etc"; RegMatch("\\((.+)\\)", s, 'm', 'n'); m; n; RegSubs(m = n, s)

"(ABC) etc"

 

true

 

"(ABC)"

 

"ABC"

 

"(ABC) etc"

(2)

``

In the second case RegSubs treats the expression m as containing special characters. Can one tell it to treat what it receives as a literal string - perhaps some "escape" function?
 

Download regsubs_problem.mw

EDIT  There is such a function. Escape(m, 'regexp') suffices.

 

Please Wait...