0

How can i reach the i th character in a string using regular expressions?

For eg:

I have a string like this:

Jack,Jill,Mary,John,Joey

I want to reach the 2nd occurrence of comma and pick up the string between the 2nd and 3rd occurrence of comma, i.e. my regular expression should give me "Mary".

Is there any way this can be done using regular expressions?

1 Answers1

5

You can use this regex to capture text between 2nd and 3rd comma:

^(?:[^,]*,){2}([^,]*)

Online Demo: http://regex101.com/r/qU7fP7

anubhava
  • 761,203
  • 64
  • 569
  • 643