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
  • 357,413
  • 63
  • 732
  • 636
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,709
  • 1
  • 20
  • 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,015
  • 2
  • 15
  • 21