Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Regular Expression Help (Searching name patterns)  (Read 13246 times)

0 Members and 1 Guest are viewing this topic.

ghostdog74



    Specialist

    Thanked: 27
    Re: Regular Expression Help (Searching name patterns)
    « Reply #15 on: September 01, 2010, 05:22:40 AM »
    I'm not  understanding the reasoning of building a regex pattern that specifically masks upper case letters (Mister, Miss, M) and then directing the regex engine to run in case insensitive mode.
    You are not wrong. Initially, i was only doing for Mr, Mrs, Ms so i used character class. Later on, I found that i have to do Mister, Miss etc so I chose to use -i, without changing those upper cases. :)

    Mister, Miss can be written as mister, miss, since I am using the -i option anyway.  Same as [Mm]. It can be written just without character class. so essentially its just

    Code: [Select]
    grep -Pio "(m[rs][s]*\.*|mister|miss)\s+\w+[- \t,]*\w+[ \t]*" file


    CBMatt

    • Mod & Malware Specialist


    • Prodigy

    • Sad and lonely...and loving every minute of it.
    • Thanked: 167
      • Yes
    • Experience: Experienced
    • OS: Windows 7
    Re: Regular Expression Help (Searching name patterns)
    « Reply #16 on: September 01, 2010, 07:21:57 AM »
    Wow he's really desperate for Troll food!  ::)



    Then why continually feed him?
    Quote
    An undefined problem has an infinite number of solutions.
    —Robert A. Humphrey

    Circuit_Girl

      Topic Starter


      Rookie

      Re: Regular Expression Help (Searching name patterns)
      « Reply #17 on: September 01, 2010, 12:05:08 PM »
      Yes ghost dog, I am still learning I have been since I have been born.  All is what I needed was help with just the regex to use but I figured it out.  I have a difficult time with just the expressions the the programming with them.

      ghostdog74



        Specialist

        Thanked: 27
        Re: Regular Expression Help (Searching name patterns)
        « Reply #18 on: September 01, 2010, 05:37:08 PM »
        Yes ghost dog, I am still learning I have been since I have been born.  All is what I needed was help with just the regex to use but I figured it out.  I have a difficult time with just the expressions the the programming with them.
        its good to learn them, but they are also not the holy grail. regex performs string manipulations for you "behind the scenes", using its own language. For example, check for beginning of line starting with "ABC" --> /^ABC/.

        In your favourite language, for example if i were to do it in Python,

        Code: [Select]
        if string.startswith("ABC") or if string[:3]=="ABC"
        The logic behind is to do a substring from first character to 3rd and perform a comparison with "ABC". Likewise, with other operations, you are able to do it just with using your language's own string manipulation functions.



        Circuit_Girl

          Topic Starter


          Rookie

          Re: Regular Expression Help (Searching name patterns)
          « Reply #19 on: September 02, 2010, 12:44:35 AM »
          That line of ghost and sidewinder left was exactly what I was looking for.  thanks for all your help.  I did get it working.  I am also going to check that program out that sidewinder posted.