Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 5th, 2013, 11:38 PM
Germaris Germaris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205 Germaris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 22 h 19 m 6 sec
Reputation Power: 10
Write and use a regular expression in PHP

Hi there!

I wish to extract from texts some chunks which always are build on the same way or, if you prefer, on the same "pattern".
So, it will be useful for me to know how to write and use a regex which will be able to find as a whole:

- a first group of characters: upper or lowercase, spaces (always followed by a letter), some quotation marks and/or dashes but no numbers.
- a space always followed by a number (may be used as a kind of "delimiter" ??? between the two groups)
- a second group of characters: numbers, dashes (always), interrogation mark (sometimes) but no spaces and no letters.

Examples :

L'Arbresle-sur-le-Lac 2345-6789

or

Saint-Denis l'Église 1234-?

Select from, and print to, a MySQL Table.
This regex will be used in a PHP script to extract the text matching the regex and write it in another column of the Table.

I am not familiar at all with preg_xxxx and don't understand how to write my query to use the regex...

:-(

Many thanks in advance for your help and/or advices!

Last edited by Germaris : February 6th, 2013 at 05:46 AM.

Reply With Quote
  #2  
Old February 6th, 2013, 05:56 AM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Posts: 2,476 ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 4 h 42 m 37 sec
Reputation Power: 2194
__________________
I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!

Reply With Quote
  #3  
Old February 6th, 2013, 07:18 AM
Germaris Germaris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205 Germaris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 22 h 19 m 6 sec
Reputation Power: 10
Thanks for replying!

Ha, ha, ha !!! Good advice which makes sense.

However, it's urgent to solve my problem and, sorry, I don't have the time for starting to study something some people take weeks or months to learn...
I assume you'll understand that.

And, believe me, even at the age of 72, I'm not a lazy person!
I already wrote:

Code:
([[:alpha:]-\'\s]+) ([0-9]+)-([0-9]+|\?)


but it doesn't work.
MySQL returns:
#1139 - Got error 'invalid character range' from regexp

Last edited by Germaris : February 6th, 2013 at 07:23 AM.

Reply With Quote
  #4  
Old February 6th, 2013, 11:32 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2004
Posts: 2,224 paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 9 h 15 m 9 sec
Reputation Power: 201
maybe show the sql query so we know what you are doing..

Reply With Quote
  #5  
Old February 6th, 2013, 11:53 AM
Germaris Germaris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205 Germaris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 22 h 19 m 6 sec
Reputation Power: 10
Quote:
Originally Posted by paulh1983
maybe show the sql query so we know what you are doing..


Thanks for replying, paulh1983!

Here is the query:

Code:
SELECT ID, longName, notes
FROM `_a_listregex`
WHERE notes REGEXP '([a-zA-Z][\-\É\é\è\'\s]+) ([0-9]+)-([0-9]+|\\?)'
ORDER BY ID


Meanwhile, I worked on this problem.
Now, it works, but not as expected.

I know that the query should return at least 2500 results.
It only returns a mere 800...

Now, my problem is to find out why it ignores some chunks and not others...
Eliminating escaped accented letters doesn't change returned results.

Reply With Quote
  #6  
Old February 8th, 2013, 12:03 PM
Germaris Germaris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205 Germaris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 22 h 19 m 6 sec
Reputation Power: 10
I gave you the query as requested...

And now, what?
Just tell me if you give up...
Thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Write and use a regular expression in PHP

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap