I want to get last occurrence from multiple occurrences of a character in LibreOffice Calc.
For e.g. I have a string abc1ba2ac2adeaa43add
. Now if I am searching for a
it should return 18.
I want to get last occurrence from multiple occurrences of a character in LibreOffice Calc.
For e.g. I have a string abc1ba2ac2adeaa43add
. Now if I am searching for a
it should return 18.
Use regex:
=SEARCH("a[^a]*$"; CELL)
To search for another character than a, simply replace both a's with the character you want to search for.
here's one that i cooked up recently - it answers the question without using regex (which for some reason, i couldn't get to work with libreoffice 4.3.1.2)
=FIND("+|",SUBSTITUTE(A1,"a","+|",(LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))))
basically, it does the following:
replace the last instance of a particular search string with a marker
SUBSTITUTE( A1, "a", "+|", (LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))) )
find the index of the marker
FIND( "+|", ... )
- or to return the string to the right of 'a' -
=MID(A1, FIND("+|",SUBSTITUTE(A1,"a","+|", (LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))))+1, LEN(A1))
in this example, "a" is the last instance of a string you're looking for and "+|" is a placeholder that musn't already exist in the string you are searching
everything trailing the spec'd string is returned by the call to mid