473,808 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ 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 1979
Is there anything better than: 'earns \$\d+\.*\d* from' ?

"George Yachán" <2m*******@wher ever.com> wrote in message
news:Oq******** ********@TK2MSF TNGP11.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.Reg ularExpressions .Regex(pattern)

Debug.WriteLine (theRegex.IsMat ch("earns $21..25 from"), "$21..25")
Debug.WriteLine (theRegex.IsMat ch("earns $21.25 from"), "$21.25")
Debug.WriteLine (theRegex.IsMat ch("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.Reg ularExpressions .Match =
theRegex.Match( "earns $21.25 from")
Debug.WriteLine (theMatch.Group s("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*******@wher ever.com> wrote in message
news:Ot******** ********@tk2msf tngp13.phx.gbl. ..
Is there anything better than: 'earns \$\d+\.*\d* from' ?

"George Yachán" <2m*******@wher ever.com> wrote in message
news:Oq******** ********@TK2MSF TNGP11.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******** ******@TK2MSFTN GP15.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.Reg ularExpressions .Regex(pattern)

Debug.WriteLine (theRegex.IsMat ch("earns $21..25 from"), "$21..25")
Debug.WriteLine (theRegex.IsMat ch("earns $21.25 from"), "$21.25")
Debug.WriteLine (theRegex.IsMat ch("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.Reg ularExpressions .Match =
theRegex.Match( "earns $21.25 from")
Debug.WriteLine (theMatch.Group s("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*******@wher ever.com> wrote in message
news:Ot******** ********@tk2msf tngp13.phx.gbl. ..
Is there anything better than: 'earns \$\d+\.*\d* from' ?

"George Yachán" <2m*******@wher ever.com> wrote in message
news:Oq******** ********@TK2MSF TNGP11.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
1613
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. The following code works for a single word: def createStandaloneWordRegex(word): """ return a regular expression that can find 'peter' only if it's written alone (next to space, start of string, end of string, comma, etc) but
3
2150
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 code snipet: my $fh = new FileHandle('c:\Units.txt') ; ## sucks up my work file my @lines1 = <$fh>; ## assigns the filehandler contents to @lines1 foreach $string (@lines1) ## extract each line from @lines and put it
4
3235
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 over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no specific format and I have to detect and remove them using a list of strings that may appear as...
11
5398
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, I want to use the text included within the brackets to do a lookup so that I can replace the expression with the new text. For example:
18
3047
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
3834
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 want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
25
5178
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 (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
4
2485
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 will return 1 (TRUE). Are there some examples I can see, do you have ideas how to start with this, and so on... GNU C regexp is to big and complicated for me, it takes a lot of space (i need this for the use in embedded system). I'll...
1
4390
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 the first regular expression that matches the string. I've gor the regular expressions ordered so that the highest priority is first (if two or more regular expressions match the string I want the first one returned) The code that does this has...
1
3412
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 "": --------------------------------- myStringVar = myStringVar.replace("^" + iName + "=,($|&)", ""); --------------------------------- The following DOES replace it though: --------------------------------- var match = myStringVar.match("^" + iName + "=,($|&)");
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9195
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
7651
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
6880
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
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
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
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.