February 5th, 2013, 11:38 PM
Write and use a regular expression in PHP
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.
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:
don't be a help vampire
February 6th, 2013, 07:18 AM
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:
but it doesn't work.
#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
Thanks for replying, paulh1983!
Originally Posted by paulh1983
Here is the query:
Meanwhile, I worked on this problem.
SELECT ID, longName, notes
WHERE notes REGEXP '([a-zA-Z][\-\…\ť\Ť\'\s]+) ([0-9]+)-([0-9]+|\\?)'
ORDER BY ID
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
I gave you the query as requested...
And now, what?
Just tell me if you give up...