in reply to string matching condition not working fine

([^g]\w+)

...any other alphabet but not g

Your example actually matches 'any character not g, followed by one or more alphanumeric characters'. You might prefer:

([a-fh-zA-FH-Z]\w*)

(assuming you wanted any alphanumeric characters being allowed in the name) ... if you only wanted alphabetic, try using

([a-fh-zA-FH-Z][a-zA-Z]*)