473,662 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2524
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.n et 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
2337
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 special letters for some language (i.e. french) are not captured. The '\w+' works fine, but it also include numerics, which I don't want. TIA
1
1281
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 use regex but am struggling with the syntax... I thought postcode REGEXP '( )' might do
6
1945
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: ------------------------------------------------- function findNumeric(str_obj){ regEx = /\d/; if (str_obj.match(regEx))
4
9744
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 numeric value according to an arbitrary regular expression.
8
1820
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 string contains two plus signs "+". Should this be a seperate RegEx or can one RegEx check for both signs? Thanks!
24
14406
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 phone numbers, and emails and addresses even person names. I need to sift through all this data (roughly 300,000+ records and use fuzzy logic to break it down, so that i have only unique records.
11
3098
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 a hand? import regsub
6
9662
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 words "this is a .5k example" goes to "this is a 500 example" The replace should not touch '.5k' that occurs inside a word. For example:
3
1555
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(-) string pattern=@"^*(+)*(+(+)*)?@*\.(*(\.*)?)$"; Modified the same t o
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.