Regex to check for numbers with minus and a letter behind them?

S

Smokey Grindel

Alright so I have a string... that can be anything like this then have a
number like 102.34m, yes there is a m behind it to say "this is money", no I
didn't design the spec thats just how data comes in... well I had a regex
that replaces all those m's in a string where there is a number before it
with no m... so its just the string with 102.34... well this worked fine
until we got negative money! so now when its -102.34m it still has the m...
here is my original regex replace string... any idea on how to change it so
that negative numbers work also? this regex seems to work ok now... (im not
great at regex's... this one took some thinking on my part to figure out so
im not even sure its entirely correct! but it seems to do what i want it
to)... any help would be GREAT! thanks!

/* Look for numbers in a string that have a m behind them and replace the m
with a null string character or space */
(?<=(^|\s)\d*\.\d*)m

/* This needs to be modified to include negative numbers as the thing it is
looking for in addition to posative numbers that are before the m to replace
with a blank string */
 
T

Thiago Macedo

/* Look for numbers in a string that have a m behind them and replace the m
with a null string character or space */
(?<=(^|\s)\d*\.\d*)m

if is said that this works, simply by adding a minus sign optional
match before yours digits would work.

(?<=(^|\s)-?\d*\.\d*)m

Thiago
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top