How to correct unbalanced parenthesis error in regular expression?

前端 未结 2 1002
渐次进展
渐次进展 2021-01-22 20:30

I am learning regular expression through Al Sweigart\'s automate the boring stuff course on udemy, lesson 29. I get an error saying \"unbalanced parenthesis at position 414 (lin

相关标签:
2条回答
  • 2021-01-22 20:50

    You need to fix this line (\d{2,5}))? # extension number part (optional). Clearly it needs to either add/remove a parenthesis.

    Changing that line to (\d{2,5})? will fix the unbalanced parenthesis error.

    0 讨论(0)
  • 2021-01-22 20:57

    Please note the unbalance that will probably give you an idea how to fix it.

         # Types of number 415-555-0000, 555-0000, (415) 555-0000, 555-0000 ext 12345,
         # ext. 12345, x12345
         (                             # (1 start)
              (                             # (2 start), area code (optional)
                   ( \d\d\d )                    # (3)
                |  ( \( \d\d\d \) )              # (4)
              )?                            # (2 end)
              ( \s | - )                    # (5), first separator
              \d\d\d                        # first 3 digits
              -                             # separator
              \d\d\d\d                      # last 4 digits
              (                             # (6 start), extension word part (optional)
                   (                             # (7 start)
                        ext
                        ( \. )?                       # (8)
                        \s
                   )                             # (7 end)
                |  x
              )                             # (6 end)
              ( \d{2,5} )                   # (9), extension number part (optional)
         )?                            # (1 end)
    =    )  <-- Unbalanced  ')'
    
    0 讨论(0)
提交回复
热议问题