Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^5: regex to return line with name but not if it has a number

by Anonymous Monk
on Apr 03, 2017 at 17:35 UTC ( [id://1186859]=note: print w/replies, xml ) Need Help??


in reply to Re^4: regex to return line with name but not if it has a number
in thread regex to return line with name but not if it has a number

Thanks this does help! Your example above and using the following regex tester has really helped: https://regex101.com. I do have one question for you or anyone as I've been doing a lot of reading and I think I've found a simpler way to do what I want. How can I match a hyphen followed by a name with a regex? I have the following code that doesn't match. If I add an or "|" between the statements I do match but I don't want an or, I want and and.

(?:^-)(?=[A-Z]'?[-a-zA-Z]+$)

Replies are listed 'Best First'.
Re^6: regex to return line with name but not if it has a number
by Corion (Patriarch) on Apr 03, 2017 at 17:41 UTC

    What is "a name"?

    Would the following be names?

    d'Artagnan O'Reilly 't Hooft de Figuera van der Vaart

        Handling names in computers just sucks. Stuffing them into separate database fields sucks even more.

        afoken++. And since nobody appears to have linked to it yet, here's a great list of falsehoods programmers believe about names -- quite a few eye-openers on there.

      In my case my names are FistName LastName so your names above are correct but they would be first name last name combinations like: - Pat O'Reilly - Tony Smith - Jane de Figuera

        But your current regular expression does not allow for a leading ' or for multiple parts of the last name, delimited by whitespace.

        Maybe you can write a short, self-contained program that shows what regular expression you are currently using, and how, and also has some input data that you want to match and some input data that you want to reject.

        As I've tried to hint with my examples, names are much more complicated than your current approach allows, so I guess the best approach is to allow almost anything as a name.

        Don't forget hyphenated names: Vivian Smith-Smythe-Smith. (Update: Also, a generational designation suffix like III or IV may be written as 3rd or 4th, although this seems rare today.)


        Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1186859]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found