Regular expressions to check numbers with currency


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regular expressions to check numbers with currency
# 1  
Old 06-15-2009
Regular expressions to check numbers with currency

Hi All


I am struggling for the last one week on how to write a regular expression to search a number with currency (such as $ 1, 245, 000.00, Rs. 1, 00, 000.00 etc) but in vain . Please help me. Thanks in advance.

-----Post Update-----

Hi All


I am struggling for the last one week on how to write a regular expression to search a number with currency in PERL (such as $ 1, 245, 000.00, Rs. 1, 00, 000.00 etc) but in vain . Please help me. Thanks in advance

-----Post Update-----

Hi All


I am struggling for the last one week on how to write a regular expression to search a number with currency in PERL (such as $ 1, 245, 000.00, Rs. 1, 00, 000.00 etc) but in vain . Please help me. Thanks in advance
# 2  
Old 06-15-2009
below perl should be ok

Code:
while(<DATA>){
	print $1,"\n" if /(\$(?:\s*[0-9]+\s*,)*\s*[0-9]+\s*\.[0-9]+)/;
}
__DATA__
line with currency $ 1, 234, 000.00
line with currency $ 1, 255.00
line with currency $ 1, 000.00
line with currency $ 1.00

# 3  
Old 06-15-2009
can you post some sample input data and sample output pattern
# 4  
Old 06-15-2009
INPUT

Currency $2,333,230.00 .
Currency $2,333.00 .
Currency $2.50 .

STATEMENT

$_ =~ s/(\$(?:\s*[0-9]+\s*,)*\s*[0-9]+\s*\.[0-9]+)/DOLLARS/g;

OUTPUT

Currency DOLLARS .
Currency DOLLARS .
Currency DOLLARS .
# 5  
Old 06-15-2009
Your goal is to determine the type of currency? Like dollars or pounds or yen? If not, what is the goal?
# 6  
Old 06-16-2009
Exactly, you are right. The regular expression should determining the type of currency, but also understand the format of the figure (such as, one million dollar ($1,000,000.00) and one lakh rupees (Rs.1,00,000.00 etc.). (Ten lakh rupees Rs.10,00,000.00 = One million Rupees Rs. 1,000,000.00)
# 7  
Old 06-16-2009
If you need to determine just a few different currencies then use a hash table to store the symbol and its currency name:

Code:
%symbols = (
  '$' => 'US Dollars',
  'Rs' => 'Lakh Rupees',
);

If your code need to ID many currencies you might want to find a better way, maybe an existing CPAN module or a webservice.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expressions

I need to pick a part of string lets stay started with specific character and end with specific character to replace using sed command the line is like this:my audio book 71-skhdfon1dufgjhgf8.wav' I want to move the characters beginning with - end before. I have different files with random... (2 Replies)
Discussion started by: XP_2600
2 Replies

2. Shell Programming and Scripting

Regular Expressions

Hi Ilove unix and alwyas trying to to learn unix,but i am weak in using regular expressions.can you please give me a littel brief discription that how can i understand them and how to use .your response could lead a great hand in my unix love. (1 Reply)
Discussion started by: manoj attri
1 Replies

3. Shell Programming and Scripting

Regular expressions help

need a regex that matches when a number has a zero (0) at the end of it so like 10 20 120 30 330 1000 and so on (6 Replies)
Discussion started by: linuxkid
6 Replies

4. Shell Programming and Scripting

Regular Expressions

what elements does " /^/ " match? I did the test which indicates that it matches single lowercase character like 'a','b' etc. and '1','2' etc. But I really confused with that. Because, "/^abc/" matches strings like "abcedf" or "abcddddee". So, what does caret ^ really mean? Any response... (2 Replies)
Discussion started by: DavidHe
2 Replies

5. UNIX for Advanced & Expert Users

Regular Expressions

Hi, below is a piece of code written by my predecessor at work. I'm kind of a newbie and am trying to figure out all the regular expressions in this piece of code. It is really a tough time for me to figure out all the regular expressions. Please shed some light on the regular expressions... (3 Replies)
Discussion started by: ramky79
3 Replies

6. Shell Programming and Scripting

regular expressions

Hello, Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits. I have written something like this: ... (4 Replies)
Discussion started by: whatever
4 Replies

7. UNIX for Dummies Questions & Answers

regular expressions

Hi Gurus, I need help with regular expressions. I want to create a regular expression which will take only alpha-numeric characters for 7 characters long and will throw out an error if longer than that. i tried various combinations but couldn't get it, please help me how to get it guys. ... (2 Replies)
Discussion started by: ragha81
2 Replies

8. Shell Programming and Scripting

Help with regular expressions

I have following content in the file CancelPolicyMultiLingual3=U|PC3|EN RestaurantInfoCode1=U|restID1|1 ..... I am trying to use following matching extression \|(+) to get this PC3|EN restID1|1 Obviously it does not work. Any ideas? (13 Replies)
Discussion started by: arushunter
13 Replies

9. Shell Programming and Scripting

Regular Expressions

How can i create a regular expression which can detect a new line charcter followed by a special character say * and replace these both by a string of zero length? Eg: Input File san.txt hello hi ... (6 Replies)
Discussion started by: sandeep_hi
6 Replies

10. Shell Programming and Scripting

Regular Expressions

I'm trying to parse RichText to XML. I want to be able to capture everything between the '/par' tag in the RTF but not include the tag itself. So far all I have is this, '.*?\\par' but it leaves '\par' at the end of it. Any suggestions? (1 Reply)
Discussion started by: AresMedia
1 Replies
Login or Register to Ask a Question