This is a discussion on Find Name with Regular Expressions within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello I'm going to expose you my problem about regular expressions. I have a list of first names and ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello
I'm going to expose you my problem about regular expressions. I have a list of first names and last names at each line of a text: $content="Bill Clinton George W Bush Jacques Chirac John Fitzgerald Kennedy Danny De Vito"; I would like to find the last name of John. I made this function, but it works only if the last name is one word if ( eregi("John+([a-zA-Z-])+\n", $content, $reg ) ) { $identite = $reg[0]; print ">Identity: $identite<BR>"; } I would like to have the text between John and the next \n Regards, and thanks for your help, Eric Vialle |
|
|||
|
"Eric VIALLE" <eric@club-competence.net> wrote in message news:bdu8ah$5ud$1@news-reader1.wanadoo.fr... > Hello > > I'm going to expose you my problem about regular expressions. > I have a list of first names and last names at each line of a text: > > $content="Bill Clinton > George W Bush > Jacques Chirac > John Fitzgerald Kennedy > Danny De Vito"; > > I would like to find the last name of John. > > I made this function, but it works only if the last name is one word > > if ( eregi("John+([a-zA-Z-])+\n", $content, $reg ) ) > { > $identite = $reg[0]; > print ">Identity: $identite<BR>"; > } > > I would like to have the text between John and the next \n > > Regards, and thanks for your help, > > Eric Vialle > > > > Try this pattern: "John([a-zA-Z ])+\n" Note the space inside the square brackets (after 'Z'). or more generally: "[a-zA-Z] ([a-zA-Z ])+\n". Use \- in the last class [ ] to account for hyphenated last-names. NB: I haven't tested this - use at your own risk! Ru |
![]() |
| Thread Tools | |
| Display Modes | |
|
|