Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9285355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:08:30+00:00 2026-06-18T19:08:30+00:00

i am struggling with regex in Python, i would like to find the position

  • 0

i am struggling with regex in Python, i would like to find the position of the last token in a String.

Example:
“mydrive/projects/test/version01”

Now i would like to get the position of the symbol between “test” and “version01”

import re
txt = "mydrive/projects/test/version01"
p = re.compile("/^.*/(.*)$/")
m = re.search(p, txt)
m.group(0) 
#but m.group(0) delivers None

but with this i am getting “None” i tried several things, but couldn’t get it find the pattern. By the way i got this regex from a javascript page, but i think the patterns are the same.

thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:08:32+00:00Added an answer on June 18, 2026 at 7:08 pm

    You say: Now i would like to get the position of the symbol between “test” and “version01”.

    I don’t see how the regex is going to help you much. You could try the following:

    Reverse scan for the symbol, if you know what the symbol is (I am assuming you do, since it is in the regex too):

    >>> txt = "mydrive/projects/test/version01"
    >>> txt.rfind('/')
    21
    

    If you don’t know the separator:

    >>> import os.path
    >>> len(os.path.dirname(txt))
    21
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling with a regex, here's an example of the input string test#string=val i
I'm struggling to find out a simple python regex, which would mean : several
Hi I'm struggling with some regex I've got a string like this: a:b||c:{d:e||f:g}||h:i basically
I'm struggling with a RegEx, and I hope to find some guidance here. I
I'm struggling with a RegEx to change a date/time string to a timestamp. The
I am not so good with regex. I am struggling to find a solution
I'm struggling to create a sed regex command to change lines like this: In
I am being struggling with this regex expression long time but i cannot find
I'm really struggling with regex here. Using Java how would I go about replacing
I am struggling with string replacement that contains special regex characters. I got a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.