#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    4
    Rep Power
    0

    Regex to filter specific words


    Hi,

    I want to filter specific words.

    These word are legal and should be found:

    J.Doe (One charater in the first place, a dot in the second place followed a sequence of characters)
    J.Doe-Doe (contains a "-", no matter in which place)

    These not e.g.:

    J.Doe1 (a sequence of characters with a number)
    JDoe (a sequence of characters without a dot in second place)
    1234 (a sequence of numbers)
    JD.Doe
    J1Doe
    etc.

    I am new in Regex and don't know how to create a proper formula.

    Thank you very much in advance for your help.

    Kind regards
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    20
    Rep Power
    0
    try
    Code:
    [A-Z]\.[A-Z][a-z]+(?:-[A-Z][a-z]+)?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    4
    Rep Power
    0
    Thank you very much for your response but that doesn't work for me 100%.
    I tried that Link with the following result:

    #1 J.Doe
    #2 J.Doe-Doe
    #3 J.Doe1
    #4 JDoe
    #5 1234
    #6 JD.Doe
    #7 J1Doe

    #1 is legal, WORKS
    #2 is legal but when I put the "-" in another (e.g. the end of the string) place it's excluded
    #3 that string has to be not legal but only the 1 is excluded
    #4 is not legal, WORKS
    #5 is not legal, WORKS
    #6 is partial legal, but it shouldn't because there are 2 characters in the beginning
    #5 is not legal, WORKS

    Regards
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    20
    Rep Power
    0
    try

    Code:
    \b[A-Z]\.[A-Z][a-z]+(?:-[A-Z][a-z]+)?\s
    Last edited by rodiavel; May 19th, 2016 at 03:26 AM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    4
    Rep Power
    0
    Good Morning rodiavel,

    the first 2 strings (#1, #2) are legal. So at first it seems to be working.
    But if I put the "-" in another postion or an additional "-" in the end it doesn't work.

    e.g.:

    #1.1 J.Doe-
    #2.2 J.DoeDoe-
    #2.3 J.Doe-Doe-

    The "-" must be legal in the part of the string after the dot.

    By the way: Casesensitivity is not necesarry, but thanks for the detail. (So I learned this too).

    Kind regards and thank you very much previous work!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    20
    Rep Power
    0
    Code:
    \b[A-Z]\.[A-Z][a-z]+(-[A-Z][a-z]+|[A-Z][a-z]+-|-)?\s
    Last edited by rodiavel; May 19th, 2016 at 04:14 AM.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    4
    Rep Power
    0
    Even if you don't talk to much, thank you VERY MUCH for your work.
    That works and I have learned a lot!

    Kind regards

IMN logo majestic logo threadwatch logo seochat tools logo