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

  • Home
  • SEARCH
  • 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 8019231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:19:26+00:00 2026-06-04T21:19:26+00:00

A newbie in regex here, I will appreciate any help. cstring = [0,90,(+45,45)3,0/]S regex

  • 0

A newbie in regex here, I will appreciate any help.

cstring = "[0,90,(+45,45)3,0/]S"
regex = re.compile(r'^(\[)(\S+)(\/?)(\][ST]$)')
match = regex.search(cstring)
for s in match.groups():
    print s

The results are “[” “0,90,(+45,45)3,0/” “]S” but I would like to get “/” in a separate (and optional – the only one from the above) group. I’ve tried to replace \S with any combinations like [0-9(),+-] – (these are the only characters expected in the second group) but no avail.

  • 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-04T21:19:29+00:00Added an answer on June 4, 2026 at 9:19 pm

    Regex quantity specifiers + and * are greedy, you can add a ? onto the end of them (+? and *?) to turn them into their non greedy forms.

    Greedy means that the operator will try consume everything it can before checking the next token.

    so for the case of

    \S+\/?
    

    The S will try consume everything it can before the / is checked, and as the / is optional nothing needs to be done for it.

    Once we make it into its non greedy form

    \S+?\/?
    

    The S will consume as little as possible before trying the / meaning that the / gets ‘first dibs’ on any tokens, and once it fails to grab them these tokens will be tried against the \S+?

    I found success using the following:

    regex = re.compile(r'^(\[)(\S+?)(\/?)(\][ST]$)')
    

    For more information you can see the python re docs search for greedy.

    As a side note if you pass the re.VERBOSE flag into re.compile then it will ignore whitespace within your string meaning you can structure it as

    regex = re.compile(r'^ (\[) (\S+?) (\/?) (\][ST]$) ', re.VERBOSE)
    

    which I found quite helpful when learning regex.

    Also you have the start of string token outside a group ‘^ ([‘ but the end of string token within a group ‘(][ST]$)’, this shouldn’t make a difference except to readability.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a regex newbie, but I understand how to match any characters in a
I am newbie to Javascript. What regex will be used to match the following
I am a regex newbie and can't seem to figure this one out. Here
Newbie question here but for some reason I cant figure this out. I have
Perl newbie here...I had help with this working perl script with some HASH code
I was reading about regular expressions (I'm a regex newbie, but want to learn
I'm a newbie to regex. Here's the pattern that I could think of :
I'm a regex newbie, please help me out. The string below occurs in one
Newbie here. I am trying to store the result of my search onto a
Newbie Regex question / C#: Consider (.*)=(.*) and how it would match 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.