Python Forum
Recursive regular expressions in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive regular expressions in Python
#3
(Jul-25-2023, 11:07 AM)deanhystad Wrote: I'm pretty sure you saw the explanation here:

https://stackoverflow.com/questions/2638...n-in-regex

I thought it was pretty good.

Hi!

Yes, I came across that at some point. However, what I don’t understand is why we need the closing bracket in the character group. Why can’t the regex be /{(?:[^{]|(?R)*)/}? Aren’t we starting a recursive call every time we encounter a closing bracket as well? Why is that desired? Shouldn’t we start a recursive call only when we find an opening bracket and expect it to be matched by the \} part of the regex? I can’t understand why the regex with the closing bracket in the character group does not lead to infinite recursion, since, when we encounter the closing bracket, we make a recursive call, and that closing bracket is not matched again, leading to a new recursive call and so on. What am I missing here?

Thanks a lot for replying.
Reply


Messages In This Thread
RE: Recursive regular expressions in Python - by risu252 - Jul-25-2023, 12:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Use or raw string on regular expressions Zaya_pool 5 520 May-09-2024, 06:10 PM
Last Post: Zaya_pool
Information Do regular expressions still need raw strings? bobmon 3 503 May-03-2024, 09:05 AM
Last Post: rishika24
Sad Regular Expressions - so close yet so far bigpapa 5 1,204 May-03-2023, 08:18 AM
Last Post: bowlofred
  Python Regular expression, small sample works but not on file Acernz 5 3,132 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Having trouble with regular expressions mikla 3 2,786 Mar-16-2021, 03:44 PM
Last Post: bowlofred
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,793 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  Regular Expressions pprod 4 3,285 Nov-13-2020, 07:45 AM
Last Post: pprod
  Format phonenumbers - regular expressions Viking 2 2,053 May-11-2020, 07:27 PM
Last Post: Viking
  regular expressions in openpyxl. format picnic 0 2,594 Mar-28-2020, 09:47 PM
Last Post: picnic
  Unexpected (?) result with regular expressions guraknugen 2 2,358 Jan-18-2020, 02:33 PM
Last Post: guraknugen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020