regex - Finding the last (rightmost) match for an arbitrary regular expression in ruby -
I am working on a text editor in Ruby, and I regularly support the "Find" feature provided by the user The expression pattern here is a simple (familiar) use-case here:
The user who is editing a text file, and somewhere in the middle of the file is in the cursor position . He wants to search back from the existing cursor location to match arbitrary regular expression.
I think this problem is equivalent to applying a user's application before the cursor-space in the file before the pattern on the whole string. Sure, I could loop through all the matches from the beginning of the file and could use the last match, but it is unable to pain ... it would be better to find "left to right", but I have to do this Can not you find the way you can help with this Ruby Reggae?
Use the rindex method on your string like this:
& Gt; & Gt; 'SsBssBss'.Rindex (/ b /) = & gt; 5
Comments
Post a Comment