I need a regular expression to match the forth comma from the end of the line, my line end in a comma.
For example, I'd like to select the comma after the G in the line below:
A,B,C,D,E,F,G,H,I,J,
I need a regular expression to match the forth comma from the end of the line, my line end in a comma.
For example, I'd like to select the comma after the G in the line below:
A,B,C,D,E,F,G,H,I,J,
You can use a quantifier and then backtrack:
Single-line input version (No newlines)
/.*\K,(?=(?:[^,]+,){3})/
Single-line matching version: (Newlines present)
/.*\K,(?=(?:[^,\n]+,){3})/
Multi-line matching version:
/.*\K,(?=(?:[^,]+,){3})/s