Input :
Hello my name is X. Blah Blah Blah
EDIT 1: Any user can enter his name substituted with X. So X is a variable with variable lenght.
Required Output :
Hello my name is Ahmed
Where X = Ahmed
Pattern :
(Hello my name is .+)\.
Really, this’s a newbie question 🙁 ,, I just start learning.
Not Working !
I really have no clue what your pattern is attempting to accomplish, so I will start at the beginning. What you want to do is to match
Hello my name is X. We can do that like so.But we don’t want to capture the letter X, we want to match what would be in X’s place. So now our regex becomes.
So the former regex now matches any character one or more times. Now we want to capture that and use it outside of the regex. We can do this with the capture,
(), operator.Now the question is, “How do we get the capture?” Well
Regex.Matchreturns aMatch. NowMatchhas a property calledGroupswhich is a collection of all the captures from the regex. So our final, code is.