I am looking for regular expression to get the match as "HELLO" and "WORLD" separately when the input is any of the following:
"HELLO", "WORLD"
"HELL"O"", WORLD"
"HELL,O","WORLD"
I have tried few combination but none of them seem to work for all the scenarios.
I am looking to have my c# code perform something like this:
string pattern = Regex Pattern;
// input here could be any one of the strings given above
foreach (Match match in Regex.Matches(input, pattern))
{
// first iteration would give me Hello
// second iteration would give me World
}
If you only require it on Hello and World I suggest Sebastian’s Answer. It is a perfect approach to this. If you really are putting other data in there, and don’t want to capture Hello and World.
Here is another solution:
^([A-Z\”\,]+)[\”\,\s]+([A-Z\”\,]+)$
The only thing is, this will return HELLO and WORLD with the ” and , in it.
Then it us up to you to do a replace ” and , to nothing in the output strings.
Example:
First and Second would be Hello and World.
Hope this helps. Let me know if you need any further help.