1

I am working with html files which have item 1, item 1a and item 2. is there a way to search backwards and find the item 1a which comes before an item 2?

example:

text= """ this is an example item 1a thanks for helping item 2 blah blah item 1a""" 
falsetru
  • 336,967
  • 57
  • 673
  • 597
mehrblue
  • 35
  • 1
  • 4

2 Answers2

5

Use str.rfind() method to search for the occurence of a string in the reverse direction. This question should also give you some insight on how to go about

Community
  • 1
  • 1
Prahalad Deshpande
  • 4,413
  • 1
  • 19
  • 22
0

yes... use the 'r' functions:

text= """ this is an example item 1a thanks for helping item 2 blah blah item 1a"""
text.rfind("1a")
Nick Dickinson-Wilde
  • 1,007
  • 2
  • 15
  • 21