Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

RegEx: Match nth occurrence

I have the following string:

_name=aVlTcWRjVG1YeDhucWdEbVFrN3pSOHZ5QTRjOEJZZmZUZXNIYW1PV2RGOWYrczBhVWRmdVJTMUxYazVBOE8zQ3JNMmNVKzJLM2JJTzFON3FiLzFHUE0xY0pkdz09LS1jbkkwaWoxUUl3YVhMMkhtZHpaOW13PT0"%"3D--57356371d167f"

I want to match everything between = and the end " (note there are other quotes after this so I can't just select the last ").

I tried using _name=(.*?)" but there are other quotes in the string as well. Is there a way to match the 3rd quote? I tried _name=(.*?)"{3} but the {3} matches for the quotes back to back, i.e. """

You can try it here

Answer*

Cancel
2
  • This solution even matches _name= along with the required match which we don't want! so shouldn't we just add a bracket around like this: _name=((?:[^"]*"){3}) regex101.com/r/oK0eO2/374 Please tell me if I got this wrong? Commented Jun 21, 2021 at 21:31
  • If you want to capture part after = then _name=((?:[^"]*"){3}) seems correct.
    – anubhava
    Commented Jun 23, 2021 at 6:08