Python Forum
Regex - Pass Flags as a function argument?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex - Pass Flags as a function argument?
#4
Can you please remove the phone numbers from your post. They are real phone numbers. I forgot to remove them before posting.

Thanks.

(Sep-04-2021, 09:02 PM)snippsat Wrote: Like this,so if look regex source code they do same with flags=0.
This is kind of double up just use the search function Confused
import re

def search(pattern, string, flags=0):
    result = re.search(pattern, string, flags) # I want to pass these as an argument to the 'search' function.
    if result is None:
        return None
    else:
        return result

if __name__ == '__main__':
    string = "This is a string with two phone numbers "
    pattern = r"\d{3}-\d{3}-\d{4}"
    flags = re.VERBOSE | re.IGNORECASE
    result = search(pattern, string, flags)
    print(result)
The argument given has to be same format then get parsing | for free.
Them do some magic to join | in parameter,just to take out 2 lines.
res = '|'.join(members)
globals().update(RegexFlag.__members__)
Reply


Messages In This Thread
RE: Regex - Pass Flags as a function argument? - by muzikman - Sep-06-2021, 02:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 597 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  How to pass encrypted pass to pyodbc script tester_V 0 980 Jul-27-2023, 12:40 AM
Last Post: tester_V
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,247 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 2,107 Nov-06-2022, 04:28 AM
Last Post: Skaperen
Question How to pass a method as argument in an another method? anilanvesh 6 2,890 Sep-30-2021, 10:18 PM
Last Post: deanhystad
  Passing flags to python script, through a function xbit 4 4,153 Apr-20-2021, 06:32 AM
Last Post: ndc85430
  Confused with 'flags' tester_V 10 5,163 Apr-12-2021, 03:03 AM
Last Post: tester_V
  Possible to dynamically pass arguments to a function? grimm1111 2 2,319 Feb-21-2021, 05:57 AM
Last Post: deanhystad
  How to use a tuple as an argument of a function zarox 5 3,917 Nov-14-2020, 08:02 PM
Last Post: buran
  calling a function and argument in an input phillup7 3 2,731 Oct-25-2020, 02:12 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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