I want to extract the return value from a given text that represents a method.
for example:
g: x and: y
Transcript show: x; show: y.
^x+y.
so to solve I used the regular expression:
\^\s*(\w+.*).
when I run this on some regex websites it seems to work and do what I want, for example : https://regex101.com/
but when I run the following program it seems that squeak returns nil
to it (can't find a match). I suspect that is because I am using the character ^
.
but I escaped that character so I have no idea why that is failing to work.
the code I used to test it:
|aString regexObj |
aString := 'g: x and: y
Transcript show: x; show: y.
^x+y.'.
regexObj := '\^\s*(\w+.*).' asRegex.
regexObj matches: aString.
returnedType:= (regexObj subexpression:2).
Transcript show: returnedType.
anyone knows why, and how to solve it?
Thanks.