I have URL, e.g. google.com/page1/page2/abc123 and my output should be abc123.
            Asked
            
        
        
            Active
            
        
            Viewed 66 times
        
    -3
            
            
         
    
    
        β.εηοιτ.βε
        
- 33,893
- 13
- 69
- 83
 
    
    
        Melisko
        
- 7
- 
                    1So, you want the last part of the URL when split by `/`? – β.εηοιτ.βε Apr 25 '23 at 09:54
- 
                    1Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Apr 25 '23 at 09:55
- 
                    2It would be simpler to understand, when posting a [example] of your Jinja-template, the given input and the desired output. – hc_dev Apr 25 '23 at 10:09
2 Answers
0
            
            
        You could try to split the url address into a list and then get the last element of that list which would be what you need.
url = "google.com/page1/page2/abc123"
splitted_url = url.split("/")
last_element = splitted_url[-1]
print(last_element)
 
    
    
        Marcin
        
- 302
- 3
- 11
0
            
            
        You have several options. One would be to split the URL into tokens based on '/' then take the last token in the returned list. Another option would be to find the last occurrence of '/' in the string then slice the string accordingly.
URL = 'google.com/page1/page2/abc123'
print(URL.split('/')[-1])
print(URL[URL.rfind('/')+1:])
 
    
    
        DarkKnight
        
- 19,739
- 3
- 6
- 22