Regex to remove a letter after a decimal number

S

Smokey Grindel

I have an app that builds where clauses (its 3rd party) and for some reason
it adds an m after decimal numbers... so I get results like this

[NumberItem] = 45.1234m And [OtherCriteria] Like '123%' And [LastCriteria] =
'45.1234m'

well that 45.1234 should not have an m there... sure this works on data
views filters but not on SQL Server which is what the criteria needs to be
for... any regex's out there that would detect a number then look if there
is an m after it so I could replace that m with nothing but only when its a
standalone number and not like in the LastCritiera filter part? thanks!
 
R

rowe_newsgroups

I have an app that builds where clauses (its 3rd party) and for some reason
it adds an m after decimal numbers... so I get results like this

[NumberItem] = 45.1234m And [OtherCriteria] Like '123%' And [LastCriteria] =
'45.1234m'

well that 45.1234 should not have an m there... sure this works on data
views filters but not on SQL Server which is what the criteria needs to be
for... any regex's out there that would detect a number then look if there
is an m after it so I could replace that m with nothing but only when its a
standalone number and not like in the LastCritiera filter part? thanks!

I'm not that great at regex expressions, but this should match the 'm'
when the number is not enclosed with apostrophes:

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

You should be able to do a Regex.Replace(...) with that, but you might
want to do some more testing before using it in a production
environment. Like I said, I'm not an expert with regex, just a fool
with Expresso.

http://www.ultrapico.com/Expresso.htm

:)

Thanks,

Seth Rowe [MVP]
 
S

Smokey Grindel

Yeah so am I, I've been here messing with regex's trying to find a good
combo... not always easy when you don't know much about them yet... thanks
though! that gets me started

rowe_newsgroups said:
I have an app that builds where clauses (its 3rd party) and for some
reason
it adds an m after decimal numbers... so I get results like this

[NumberItem] = 45.1234m And [OtherCriteria] Like '123%' And
[LastCriteria] =
'45.1234m'

well that 45.1234 should not have an m there... sure this works on data
views filters but not on SQL Server which is what the criteria needs to
be
for... any regex's out there that would detect a number then look if
there
is an m after it so I could replace that m with nothing but only when its
a
standalone number and not like in the LastCritiera filter part? thanks!

I'm not that great at regex expressions, but this should match the 'm'
when the number is not enclosed with apostrophes:

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

You should be able to do a Regex.Replace(...) with that, but you might
want to do some more testing before using it in a production
environment. Like I said, I'm not an expert with regex, just a fool
with Expresso.

http://www.ultrapico.com/Expresso.htm

:)

Thanks,

Seth Rowe [MVP]
 

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