What is the regular expression to get the position of the last separator character before a certain pattern?
For example, I have a string as follows
some value;some other value;some special XYZ value;some more special XYZ value
Here, the separator character is semicolon (“;”) and the pattern I am looking for is any string that contains “XYZ”.
The correct answer is this case is position 28, which is the last occurence of the separator character (“;”) before an element containing the match pattern (“XYZ”).
What would the regular expression look like?
matches a semicolon that’s followed by
XYZwithin the same segment of the string.Use it once to find the first occurrence. If you use it repeatedly, you’ll find the following occurrences, too.