RegEx: Match Mr. Ms. etc in a "Title" Database field -


i need build regex expression gets text strings title field of database. i.e. complete strings being searched are: mr. or ms. or dr. or sr. etc.

unfortunately field free field , written it. e.g.: m. ; a ; cfo etc.

the expression needs match on except: mr. ; ms. ; dr. ; sr. (note: list bit longer simplicity keep short.)

what have tried far:

this using on on field:

^(?!(vip)$).* (this match every string except "vip")

i rewrote expression this:

^(?!(mr.|ms.|dr.|sr.)$).*

unfortunately did not work. assume because because of "." (dot) reserved symbol in regex , needs special handling.

i tried:

^(?!(mr\.|ms\.|dr\.|sr\.)$).*

but no luck well.

i looked around in forum , tested other solutions not find works me.

i know how can build formula search complete (short) string , matches except "mr." etc. appreciated!

note: question might seem unusual , seems have many open ends , possible errors. rest of application handling open ends. please trust me this.

if want string not start 1 of prefixes, this:

^(?!([mds]r|ms)\.).*$ 

the above ensures beginning of string (^) not followed 1 of listed prefixes. (you shouldn't need .*$ in case you're using engine requires complete match.)

if want string not have prefixes anywhere, do:

^(.(?!([mds]r|ms)\.))*$ 

the above ensures every character (.) not followed 1 of listed prefixes, end (so $ is necessary in one).


i read list of prefixes may longer, let me expand add:

^(.(?!(mr|ms|dr|sr)\.))*$ 

you entirely of prefixes? this:

^(?!mr|ms|dr|sr)\.$ 

and if want make dot conditional:

^(?!mr|ms|dr|sr)\.?$                   ^ 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -