473,480 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

simple regular expression

What would the regular expression be to return both of the following?
Thank you.

'earns $21.25 from"
'earns $21 from"
Nov 21 '05 #1
3 1944
Is there anything better than: 'earns \$\d+\.*\d* from' ?

"George Yachán" <2m*******@wherever.com> wrote in message
news:Oq****************@TK2MSFTNGP11.phx.gbl...
What would the regular expression be to return both of the following?
Thank you.

'earns $21.25 from"
'earns $21 from"

Nov 21 '05 #2
George,
Assuming you mean a number preceded by a dollar sign, I would use:

'earns \$\d+(\.\d*)? from'

As I would expect you only want a single period, and the period needs to
proceed the (optional) decimal places.

Something like:
Const pattern As String = "earns (?<amount>\$\d+(\.\d*)?) from"
'Const pattern As String = "earns (?<amount>\$\d+\.*\d*) from"
Dim theRegex As New System.Text.RegularExpressions.Regex(pattern)

Debug.WriteLine(theRegex.IsMatch("earns $21..25 from"), "$21..25")
Debug.WriteLine(theRegex.IsMatch("earns $21.25 from"), "$21.25")
Debug.WriteLine(theRegex.IsMatch("earns $21 from"), "$21")

If you use named groups as I have above, you can extra just the amount that
was matched:

Something like:

Dim theMatch As System.Text.RegularExpressions.Match =
theRegex.Match("earns $21.25 from")
Debug.WriteLine(theMatch.Groups("amount"), "amount")

The following site provides a good overview of regular expressions:

http://www.regular-expressions.info/

While this site provides the syntax specifically supported by .NET:

http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"George Yachán" <2m*******@wherever.com> wrote in message
news:Ot****************@tk2msftngp13.phx.gbl...
Is there anything better than: 'earns \$\d+\.*\d* from' ?

"George Yachán" <2m*******@wherever.com> wrote in message
news:Oq****************@TK2MSFTNGP11.phx.gbl...
What would the regular expression be to return both of the following?
Thank you.

'earns $21.25 from"
'earns $21 from"


Nov 21 '05 #3
A response from heaven! That's everything I need to know and more. Thank you
very much!!

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
George,
Assuming you mean a number preceded by a dollar sign, I would use:

'earns \$\d+(\.\d*)? from'

As I would expect you only want a single period, and the period needs to
proceed the (optional) decimal places.

Something like:
Const pattern As String = "earns (?<amount>\$\d+(\.\d*)?) from"
'Const pattern As String = "earns (?<amount>\$\d+\.*\d*) from"
Dim theRegex As New System.Text.RegularExpressions.Regex(pattern)

Debug.WriteLine(theRegex.IsMatch("earns $21..25 from"), "$21..25")
Debug.WriteLine(theRegex.IsMatch("earns $21.25 from"), "$21.25")
Debug.WriteLine(theRegex.IsMatch("earns $21 from"), "$21")

If you use named groups as I have above, you can extra just the amount that was matched:

Something like:

Dim theMatch As System.Text.RegularExpressions.Match =
theRegex.Match("earns $21.25 from")
Debug.WriteLine(theMatch.Groups("amount"), "amount")

The following site provides a good overview of regular expressions:

http://www.regular-expressions.info/

While this site provides the syntax specifically supported by .NET:

http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"George Yachán" <2m*******@wherever.com> wrote in message
news:Ot****************@tk2msftngp13.phx.gbl...
Is there anything better than: 'earns \$\d+\.*\d* from' ?

"George Yachán" <2m*******@wherever.com> wrote in message
news:Oq****************@TK2MSFTNGP11.phx.gbl...
What would the regular expression be to return both of the following?
Thank you.

'earns $21.25 from"
'earns $21 from"



Nov 21 '05 #4

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

Similar topics

4
1585
by: peterbe | last post by:
I want to match a word against a string such that 'peter' is found in "peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or "hey peterbe," because the word has to stand on its own....
3
2130
by: EFP | last post by:
Can anyone help me with a simple regular expression problem. All that I want to do is take a list of known data and extract a particular section of the string to form a new list. Here is my...
4
3200
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
11
5348
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
18
3012
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
7
3791
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
5128
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
4
2457
by: drasko | last post by:
Hi all. I need to code simple and fast int regexp_match(char *regexp, char *string) function that will follow the expression regexp, and see if there is a matching in the string. If there is, it...
1
4358
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
1
3373
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
0
7055
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,...
0
6920
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
7060
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,...
0
7106
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...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4799
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...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
572
muto222
php
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.