Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

regex

$
0
0

I have several files that I need to parse for a user's name and phone number; however, I am unable to get this data parsed out correctly. In the following code, I am trying to retrieve the fullname, but it returns the first name:

$str='empid="12345" fullname="Doe, John" phonenumber="123-456-7890" otherdata=""...'| Select-String -pattern "fullname"

$var=@($str -split "fullname=")[-1]

$var = $var -replace '"',""

"$var" -match "\w* \w*"

$Matches

The file contains the following string:

 

empid="12345" fullname="Doe, John" phonenumber="123-456-7890" otherdata=""...


Viewing all articles
Browse latest Browse all 6937

Trending Articles