Snowung
Snowung

Reputation: 115

same word with underscore in powershell

I have 2 expressions separated by an underscore. I can't create a REGEX that allows me to differentiate them.

Example:

"S_Macdo" -match "^S(?<NAME>[a-zA-Z]*)"

-> Macdo -> OK

"S_Macdo_Fries" -match "^S(?<NAME>[a-zA-Z]*)"

-> Macdo -> NOK - I need to have Macdo_Fries

Thanks

Upvotes: 2

Views: 1184

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627083

You may use

^S_(?<NAME>[a-zA-Z_]*)

See the online .NET regex demo

Details

  • ^ - start of string
  • S_ - a literal substring
  • (?<NAME>[a-zA-Z_]*) - Group "NAME" that captures 0 or more chars that are either ASCII letters or underscores.

Upvotes: 8

Related Questions