Which command should I be looking at if I want to remove strings in a variable? For example, if the variable contains "Balance (100)" I just want it to return "100" where all the alphabet and everything else are removed?
Put in mind that the string can be different, not the same at all times. It can be "Net (400)", "Input (500)", etc.
Thank you
Posts: 12,239
Threads: 144
Joined: Dec 2002
Use replacerx or findrx.
str s="Balance (100)"
s.replacerx(".+?(\d+).*" "$1" 4)
out s
Here ".+?(\d+).*" ir regular expression.
.+? is 1 or more any characters. Matches "Balance (".
\d+ is 1 or more digits. Matches "100".
() marks the part of the string that can be specified as $1 in the replacement string.
.* is 0 or more any characters. Matches ")".
Thanks, that works out great!
Posts: 129
Threads: 38
Joined: May 2006
str s="Balance is (100,323.22)"
s.replacerx(".+?(\d+).*" "$1" 4)
out s
I tried the code above and returned 100 instead of 100,323.22. What am I doing wrong?
Thanks!
Denise
Posts: 12,239
Threads: 144
Joined: Dec 2002
Replace
\d+
to
\d+(?:,\d+)*(?:\.\d+)?