How do I write a regular expression to get that returns only the letters and numbers without the asterisks in between ?
Asked
Active
Viewed 75 times
2
-
I've rolled back your deletion of most of this question and marked [your reposting](https://stackoverflow.com/questions/66033437/regular-expression) as a duplicate. I'm not sure what you were trying to achieve. – Dave Cross Feb 04 '21 at 11:41
1 Answers
1
You could use a regex replacement here:
my $var = 'RMRIV43069411**2115.82';
$var =~ s/^.*?\D(\d+(?:\.\d+)*)$/$1/g;
print "$var"; // 2115.82
The idea is to capture the final number in the string, and then replace with only that captured quantity.
Here is an explanation of the pattern:
^ from the start of the input
.*? consume all content up until
\D the first non digit character, which is followed by
(\d+(?:\.\d+)*) match AND capture: a number, with optional decimal component,
occurring before
$ the end of the input
Then, we place with just this captured number, which is available in $1
.

Tim Biegeleisen
- 502,043
- 27
- 286
- 360