0

I am trying regex to match the names in the string below:

$strText = "some text, 'Frances , David', some text, 'Foljevic, Laura M', some text, Holjevic, Louis, some text, 'Staples, Cheri L', some text"

The name must start and end with single quotation mark(') There can be optional space before and after comma sign(,) There can be first, last and middle name.

I am trying to match with the following pattern: '\w*(\s*)?, \w*(\s*\w*)?' but it fails in case of middle name.

1 Answer 1

2

Like this?

 $strText = "some text, 'Frances , David', some text, 'Foljevic, Laura M', some text, Holjevic, Louis, some text, 'Staples, Cheri L', some text"

    $result = 
    [regex]::Matches($strText,"'(.+?)'") |
    foreach {$_.groups[1].value}

    $result

    Frances , David
    Foljevic, Laura M
    Staples, Cheri L
Sign up to request clarification or add additional context in comments.

1 Comment

Hi mjolinor, Can i add output strings to some collection like $Result = @()?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.