Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Applications > regex break up numbers

regex break up numbers
Thread Tools
Senior User
Join Date: Jul 2001
Status: Offline
Reply With Quote
Oct 22, 2004, 09:28 AM
 
help please I am trying to break up a stack of numbers with regex something like

73758584585868493djruhl4957849-94759585

to something like this

7375 8584585 86849 3 d jruhl 4957 849 -947 595 85

I tried (\d\d\d\d)(\d\d\d\d\d\d\d)
\1\2
and stuff like that but I am sure I am doing someting wrong for string of numbers finding. Is there a method to find a sets amount of numbers in a string search beside \d\d\d\d ??
     
Addicted to MacNN
Join Date: Feb 2001
Location: zurich, switzerland
Status: Offline
Reply With Quote
Oct 22, 2004, 09:56 AM
 
The problem is that you don't seem to be clear about how exactly you want to break up that string. If you have a precise set based on specific rules, then regex can do it for you, otherwise you would probably be better off just using a string chunking function of a language like php or java.
weird wabbit
     
loren s  (op)
Senior User
Join Date: Jul 2001
Status: Offline
Reply With Quote
Oct 22, 2004, 10:18 AM
 
well it is just the same for every line. I was just in need of the method to break up an ammount of numbers like say a telephone number ..

2075439987 to 207 543 9987 . what would the patteren be for that ? ### ### ####???
     
Professional Poster
Join Date: Dec 2000
Location: Staffs, UK
Status: Offline
Reply With Quote
Oct 22, 2004, 11:00 AM
 
In Perl you would write something like :

s/(\d{3})(\d{3})(\d{4})/\1 \2 \3/

s is the substitute operator
the first bit between / and / is the pattern to match (and () groups the matches)
the second bit between the / and / is what to replace it with, and \1 etc refers to the first () group that matched, etc.
     
Mac Enthusiast
Join Date: Mar 2004
Status: Offline
Reply With Quote
Oct 22, 2004, 01:47 PM
 
yeah... which language are you using? that would change things a bit, perhaps. and for any one language, there are probably several ways to do it... it depends on what you are expecting for input and what you need for output.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2