The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Write and use a regular expression in PHP
Discuss Write and use a regular expression in PHP in the Regex Programming forum on Dev Shed. Write and use a regular expression in PHP Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 5th, 2013, 11:38 PM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205
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.
|

February 6th, 2013, 05:56 AM
|
|
|
__________________
I ♥ ManiacDan & requinix
This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!
|

February 6th, 2013, 07:18 AM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205
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.
|

February 6th, 2013, 11:32 AM
|
|
|
|
maybe show the sql query so we know what you are doing..
|

February 6th, 2013, 11:53 AM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205
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.
|

February 8th, 2013, 12:03 PM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|