1.2k questions

1.4k answers

361 comments

339 users

Categories

Sidebar
0 votes
549 views
by russell-c-4612 (140 points)
I have a result like OBX-5 = "1.25 fasting", I want to return to a variable just the 1.25

Everything I've tried so far, including regex is not working. Any suggestions?

1 Answer

0 votes

The StringUtils.replace() method only replaces string literals and does not accept regular expressions.  The easiest way to do this it to convert the source value to a java string and use the String.replaceAll() method.

Here is an example:

var before = "1.25 fasting";
var after = (new java.lang.String(before)).replaceAll('[A-z ]', '');
qie.debug(before);
qie.debug(after);
 

This will take the before string and replace any character between upper case A and lowercase z and any spaces with an empty string (basically removing the value).

by ben-s-7515 (13.0k points)
...