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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:01:55+00:00 2026-05-25T23:01:55+00:00

Lets say i have a regular expression: match = re.search(pattern, content) if not match:

  • 0

Lets say i have a regular expression:

match = re.search(pattern, content)
if not match:
    raise Exception, 'regex traceback' # i want to throw here the regex matching process.

If regular expression fails to match then i want to throw in exception Its working and where it fails to match the regular expression pattern, at what stage etc. Is it possible even to achieve the desired functionality?

  • 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-05-25T23:01:56+00:00Added an answer on May 25, 2026 at 11:01 pm

    I have something that helps me to debug complex regex patterns among my codes.
    Does this help you ? :

    import re
    
    li = ('ksjdhfqsd\n'
          '5 12478 abdefgcd ocean__12      ty--\t\t ghtr789\n'
          'qfgqrgqrg',
    
          '6 48788 bcfgdebc atlantic__7899 %fg#\t\t ghtu12340\n',
    
          '2 47890 bbcedefg arctic__124    **juyf\t\t ghtr89877',
    
          '9 54879 bbdecddf antarctic__13  18:13pomodoro\t\t ghtr6798',
    
    
          'ksjdhfqsd\n'
          '5 12478 abdefgcd ocean__1247101247887 ty--\t\t ghtr789\n'
          'qfgqrgqrg',
    
          '6 48788 bcfgdebc atlantic__7899 %fg#\t\t ghtu12940\n',
    
          '25 47890 bbcedefg arctic__124    **juyf\t\t ghtr89877',
    
          '9 54879 bbdeYddf antarctic__13  18:13pomodoro\t\t ghtr6798')
    
    
    tupleRE = ('^\d',
               ' ',
               '\d{5}',
               ' ',
               '[abcdefghi]+',
               ' ',
               '(?=[a-z\d_ ]{14} [^ ]+\t\t ght)',
               '[a-z]+',
               '__',
               '[\d]+',
               ' +',
               '[^\t]+',
               '\t\t',
               ' ',
               'ght',
               '(r[5-9]+|u[0-4]+)',
               '$')  
    
    
    
    def REtest(ch, tuplRE, flags = re.MULTILINE):
        for n in xrange(len(tupleRE)):
            regx = re.compile(''.join(tupleRE[:n+1]), flags)
            testmatch = regx.search(ch)
            if not testmatch:
                print '\n  -*- tupleRE :\n'
                print '\n'.join(str(i).zfill(2)+' '+repr(u)
                                for i,u in enumerate(tupleRE[:n]))
                print '   --------------------------------'
                # tupleRE doesn't works because of element n
                print str(n).zfill(2)+' '+repr(tupleRE[n])\
                      +"   doesn't match anymore from this ligne "\
                      +str(n)+' of tupleRE'
                print '\n'.join(str(n+1+j).zfill(2)+' '+repr(u)
                                for j,u in enumerate(tupleRE[n+1:
                                                             min(n+2,len(tupleRE))]))
    
                for i in xrange(n):
                    match = re.search(''.join(tupleRE[:n-i]),ch, flags)
                    if match:
                        break
    
                matching_portion = match.group()
                matching_li = '\n'.join(map(repr,
                                            matching_portion.splitlines(True)[-5:]))
                fin_matching_portion = match.end()
                print ('\n\n  -*- Part of the tested string which is concerned :\n\n'
                       '######### matching_portion ########\n'+matching_li + '\n'
                       '##### end of matching_portion #####\n'
                       '-----------------------------------\n'
                       '######## unmatching_portion #######')
                print '\n'.join(map(repr,
                                    ch[fin_matching_portion:
                                       fin_matching_portion+300].splitlines(True)) )
                break
        else:
            print '\n  SUCCES . The regex integrally matches.'
    
    
    
    for x in li:
        print '  -*- Analyzed string :\n%r' % x
        REtest(x,tupleRE)
        print '\nmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm'
    

    result

      -*- Analyzed string :
    'ksjdhfqsd\n5 12478 abdefgcd ocean__12      ty--\t\t ghtr789\nqfgqrgqrg'
    
      SUCCESS . The regex integrally matches.
    
    mwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm
      -*- Analyzed string :
    '6 48788 bcfgdebc atlantic__7899 %fg#\t\t ghtu12340\n'
    
      SUCCESS . The regex integrally matches.
    
    mwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm
      -*- Analyzed string :
    '2 47890 bbcedefg arctic__124    **juyf\t\t ghtr89877'
    
      SUCCESS . The regex integrally matches.
    
    mwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm
      -*- Analyzed string :
    '9 54879 bbdecddf antarctic__13  18:13pomodoro\t\t ghtr6798'
    
      SUCCESS . The regex integrally matches.
    
    mwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm
      -*- Analyzed string :
    'ksjdhfqsd\n5 12478 abdefgcd ocean__1247101247887 ty--\t\t ghtr789\nqfgqrgqrg'
    
      -*- tupleRE :
    
    00 '^\\d'
    01 ' '
    02 '\\d{5}'
    03 ' '
    04 '[abcdefghi]+'
    05 ' '
       --------------------------------
    06 '(?=[a-z\\d_ ]{14} [^ ]+\t\t ght)'   doesn't match anymore from this ligne 6 of tupleRE
    07 '[a-z]+'
    
    
      -*- Part of the tested string which is concerned :
    
    ######### matching_portion ########
    '5 12478 abdefgcd '
    ##### end of matching_portion #####
    -----------------------------------
    ######## unmatching_portion #######
    'ocean__1247101247887 ty--\t\t ghtr789\n'
    'qfgqrgqrg'
    
    mwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm
      -*- Analyzed string :
    '6 48788 bcfgdebc atlantic__7899 %fg#\t\t ghtu12940\n'
    
      -*- tupleRE :
    
    00 '^\\d'
    01 ' '
    02 '\\d{5}'
    03 ' '
    04 '[abcdefghi]+'
    05 ' '
    06 '(?=[a-z\\d_ ]{14} [^ ]+\t\t ght)'
    07 '[a-z]+'
    08 '__'
    09 '[\\d]+'
    10 ' +'
    11 '[^\t]+'
    12 '\t\t'
    13 ' '
    14 'ght'
    15 '(r[5-9]+|u[0-4]+)'
       --------------------------------
    16 '$'   doesn't match anymore from this ligne 16 of tupleRE
    
    
    
      -*- Part of the tested string which is concerned :
    
    ######### matching_portion ########
    '6 48788 bcfgdebc atlantic__7899 %fg#\t\t ghtu12'
    ##### end of matching_portion #####
    -----------------------------------
    ######## unmatching_portion #######
    '940\n'
    
    mwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm
      -*- Analyzed string :
    '25 47890 bbcedefg arctic__124    **juyf\t\t ghtr89877'
    
      -*- tupleRE :
    
    00 '^\\d'
       --------------------------------
    01 ' '   doesn't match anymore from this ligne 1 of tupleRE
    02 '\\d{5}'
    
    
      -*- Part of the tested string which is concerned :
    
    ######### matching_portion ########
    '2'
    ##### end of matching_portion #####
    -----------------------------------
    ######## unmatching_portion #######
    '5 47890 bbcedefg arctic__124    **juyf\t\t ghtr89877'
    
    mwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm
      -*- Analyzed string :
    '9 54879 bbdeYddf antarctic__13  18:13pomodoro\t\t ghtr6798'
    
      -*- tupleRE :
    
    00 '^\\d'
    01 ' '
    02 '\\d{5}'
    03 ' '
    04 '[abcdefghi]+'
       --------------------------------
    05 ' '   doesn't match anymore from this ligne 5 of tupleRE
    06 '(?=[a-z\\d_ ]{14} [^ ]+\t\t ght)'
    
    
      -*- Part of the tested string which is concerned :
    
    ######### matching_portion ########
    '9 54879 bbde'
    ##### end of matching_portion #####
    -----------------------------------
    ######## unmatching_portion #######
    'Yddf antarctic__13  18:13pomodoro\t\t ghtr6798'
    
    mwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwmwm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a single object of type Car which I want to
Let's say I have a regular expression that works correctly to find all of
Let's say for example that I have a regular expression like this: The quick
Let's say I have a regular simple Java class, such as: public class Foo
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say I have a Dictionary object: Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
Lets say I have several web sites on my web server, all as applications
Lets say I have an array like this: string [] Filelist = ... I
Lets say we have something like: <div class=row> <div class=box> <a class=more href=#more/> </div>

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.