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 8068835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:49:11+00:00 2026-06-05T12:49:11+00:00

How do you create a function to get the word after class only if

  • 0

How do you create a function to get the word after “class” only if it is not a quoted (by single or double, or any triple quotations) and if its spelled correctly (cannot get class d() )

"class hi()"  > hi

"class hi(dff)"  > hi

"class hi   (  dff  )  :"  > hi 

"  class        hi       (  dff  )  :"  > hi 

"class hi"  > hi

"classf hi"  > Nothing

"fclass hi"  > Nothing

"'class hi(dd)'"  > Nothing

'"class hi(dd)"'  > Nothing

"'''class hi(dd)'''"  > Nothing

'"""class hi(dd)"""'  > Nothing

'"""\n\n\n\nclass hi(dd)\n\n\n\n"""'  > Nothing    

"'class' hi()"  > Nothing

It is too hard to create using loops. If anyone can help that would be nice, thanks. This is pretty challenging,

  • 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-05T12:49:12+00:00Added an answer on June 5, 2026 at 12:49 pm
    import re
    
    def remove(reg, s, multiline=False):
        flags = [re.M, re.M | re.DOTALL][multiline]
        s,num = re.subn(reg, "", s, flags=flags)
        return s
    
    def classname(s):
        s = remove("\"\"\".*?\"\"\"", s, multiline=True)
        s = remove("\'\'\'.*?\'\'\'", s, multiline=True)
        s = remove("\".*?\"", s)
        s = remove("\'.*?\'", s)
    
        res = re.search("(^|\s)class\s+(\w+)", s, flags=re.M)
        # print "*** {} -> {}".format(s, res.groups() if res else None)
        if res is None:
            return None
        else:
            return res.group(2)
    

    I wanted to use \b instead of (^|\s) but it didn’t seem to want to work?

    I also put together the following test code:

    tests = [
        ("class hi()", "hi"),
        ("class hi(dff)", "hi"),
        ("class hi   (  dff  )  :", "hi"),
        ("  class        hi       (  dff  )  :", "hi"),
        ("class hi", "hi"),
        ("classf hi", None),
        ("fclass hi", None),
        ("'class hi(dd)'", None),
        ('"class hi(dd)"', None),
        ("'''class hi(dd)'''", None),
        ('"""class hi(dd)"""', None),
        ('"""\n\n\n\nclass hi(dd)\n\n\n\n"""', None),   
        ("'class' hi()", None),
        ("a = ''; class hi(object): pass", "hi")
    ]
    
    def run_tests(fn, tests=tests):
        for inp,outp in tests:
            res = fn(inp)
            if res == outp:
                print("passed")
            else:
                print("FAILED on {} (gave '{}', should be '{}')".format(inp, repr(res), repr(outp)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get a reference for chrome.contextMenus.create title property in onClick function. For
i want to create functions what get the folder size. I write small function:
I get this SoapFault I dont understand. Calling the function below, codewordStemExists(), should create
Django's get_or_create function always cause get() returned more than one Model name error in
I want to create a simple menu function which can call it example get_menu()
I'm trying to create two functions: get & set, that both accept an arbitrary
When we try to create a view within a funcion we get ERROR: there
I would like to get a reference back to the function that created an
I have a function that creates a course. I am trying to get the
CREATE FUNCTION [dbo].[MSG_FilterAutoship] ( @ItemID VARCHAR(50) = NULL ) RETURNS @Autoship TABLE ( DistID

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.