Reputation: 115
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
Reputation: 627083
You may use
^S_(?<NAME>[a-zA-Z_]*)
See the online .NET regex demo
Details
^
- start of stringS_
- a literal substring(?<NAME>[a-zA-Z_]*)
- Group "NAME" that captures 0 or more chars that are either ASCII letters or underscores.Upvotes: 8