I need a regular expression to match the fourth comma from the end of the line, my line ends with a comma.
For example, I would like to select a comma after G in the line below:
A,B,C,D,E,F,G,H,I,J,
You can do this using lookahead:
,(?=(?:[^,]*,){3}[^,]*$)
See how it works on the Internet: Rubular
You can use a quantifier and then return:
Single line input option (No newline)
/.*\K,(?=(?:[^,]+,){3})/
Single line matching version: (new lines displayed)
/.*\K,(?=(?:[^,\n]+,){3})/
Multi Line Compatibility:
/.*\K,(?=(?:[^,]+,){3})/s