Matty J
Matty J

Reputation: 55

Regex: Trying to match a string that contains users names

I am trying to match user names for accounts.

All out usernames only contain characters. However there are a few that contain "."

I am trying to write a expression that will match all username if they have special characters within them or not but have not go very far.

You can see from below i have 2 entry with 2 different account names. I need an expression that will match both.

So far i have this but keep getting tripped up on the special character.

Account Name:(\s\w*[.\D])

Can anyone help?

A security-enabled global group was created. Subject: Security ID: Account Name: testing Account Domain:  Logon ID:

A security-enabled global group was created.Account Name: testing.testing Account Domain:  Logon ID:  New Group: Security ID:  Group Name:  Group Domain:  SAM Account Name: SID History: 

Upvotes: 1

Views: 115

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37414

you can use Account Name:(\s[\w.]+)

[\w.]+ match 1 or more occurrences of a-zA-Z0-9_ and . character

if you need to match any special character then use Account Name:(\s[a-zA-Z]+.*)

[a-zA-Z]+ match at least 1 or more alphabet, although you can also use range {} if you have minimum characters for the username

Upvotes: 3

Related Questions