0
how can I find the index of the second repetition of a string?
f = open("newFile.txt", "w+") pathName = os.path.abspath(f.name) #I need to find the index of the second repetition of the back slash
6 Antworten
+ 5
On an index note, see here:
https://code.sololearn.com/cT1BcIt41D02/?ref=app
+ 2
Do you mean second instance, or second repetition (i.e. 3rd instance)?
I would recommend regex for this.
import re
string = 'hello//world//ygc'
print(re.match(r'(?:.*?/.*?/.*?)/', string).end() - 1) #12 3rd instance.
print(re.match(r'(?:.*?/.*?)/', string).end() - 1) #6 2nd instance.
+ 2
Kuba Siekierzyński Very nice! You win this regex round! 😉
+ 1
Russ I used to love this game :) Reminds me of some very good time in my life ;)
0
the back slash is repeated about five times in the string and I want to find the index of the second backslash.
0
I’m not really understanding. Specially the “(?:.*?/.*?)”