Hi all,
I’ve need to achieve something which on the face of it seems relatively straightforward but i’m having issues identifying a working solution.
In a column, I have a list of page numbers e.g. page 1, page2, page 3a, page 3b page 4b, page 5, page 53a…
What I need to do is replace the trailing a (& not the a in the word page) with the string “-1”. Similarly, i need to replace the trailing b with the string “-2”.
I’ve tried a few different regex but i can’t get any to work.
Does anyone have an idea of how i can do this please?
This uses regexMatcher to determine if the page reference is of the form page nx, such that n is numeric and x is alphabetic.
If that returns “True”, it uses the code from @sanket_2012 to remove the last letter, and replaces it with a numeric representing that letter (multiplied by -1), so a=>-1, b=>-2, c=>-3 and so on
In the above I’ve assumed you don’t go above “e”, but if you do, just add further letters to the “abcde” string, all the way up to “z” if need be.
edit: if you want to avoid the “ternary operator” conditional syntax of ? and : and the substr, here is an alternative: