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,
The 0-9 indicates characters 0 through 9, the comma , indicates comma, and the semicolon indicates a ; . The closing ] indicates the end of the character set.
End of String or Line: $ The $ anchor specifies that the preceding pattern must occur at the end of the input string, or before \n at the end of the input string. If you use $ with the RegexOptions. Multiline option, the match can also occur at the end of a line.
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
You can do this using a lookahead:
,(?=(?:[^,]*,){3}[^,]*$)
See it working online: Rubular
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With