473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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 */
Aug 25 '08 #1
3 2506
On Aug 25, 1:56 pm, "Smokey Grindel" <nos...@nospam.comwrote:
/* 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
Aug 25 '08 #2
On Mon, 25 Aug 2008 12:56:54 -0400, "Smokey Grindel"
<no****@nospam.comwrote:
>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 */
Try this:

^(?:|-)\d+(?:|\.\d+)m$

It matches the following test cases:

102.34m
-102.34m
100m
100.0m
-1m
-10.50m
10m
5m

Note the anchors I have added require a full match. If you want
partial matches (meaning leading and/or trailing additional characters
are okay), remove the anchors like this:

(?:|-)\d+(?:|\.\d+)m

Aug 26 '08 #3
On Tue, 26 Aug 2008 06:51:31 -0400, ja***@onepost.net wrote:

>Try this:

^(?:|-)\d+(?:|\.\d+)m$
Also, it appears you wish to capture the money amounts, so add another
set of parens around the whole thing:

^((?:|-)\d+(?:|\.\d+))m$
Aug 26 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ricky Romaya | last post by:
Hi, Anybody could show me a regex for capturing words (alphas, without numerics) in languages other than english (languages with special characters i.e. french, german)? I've tried '+' but the...
1
by: Jon Cooper | last post by:
hi folks - I know very little about regex so this is bound to be simple... I need to scan thru a db and check postcodes are in the format AB1 123, AB10 123 or A12 123. Now I know I need to...
6
by: Vishant | last post by:
Hi, I'm new to javascript and regEx and trying to solve the following problem. I have a function which validates the password if there is a number:...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
24
by: cassetti | last post by:
Here's the issue: I have roughly 20 MS excel spreadsheets, each row contains a record. These records were hand entered by people in call centers. The problem is, there can and are duplicate...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
6
by: Gary Bond | last post by:
Hi All, Being a bit of a newbie with regex, I am confused when using word boundaries. For instance, I want to replace all the stand alone '.5k' that occur in an input string, with 500. In other...
3
by: Praveen | last post by:
looking for regex pattern for validating emailid emailid can have a-z 0-9 - _ . (a to z, 0 ot 9, hyphen,undercore, dot) here is a sample which I got from net which doesnt allow hyphen(-) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.