1.

Solve : Regular Expression Help (Searching name patterns)?

Answer»

Quote from: Sidewinder on September 01, 2010, 05:14:23 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

Quote from: BC_Programmer on August 31, 2010, 01:39:59 PM
Wow he's REALLY desperate for Troll food!



Then why continually feed him?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.Quote from: Circuit_Girl 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.
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.


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.


Discussion

No Comment Found