How to pass multiline flag to re.sub without using re.complie.

Discussion in 'Python' started by samba, May 23, 2009.

  1. samba

    samba Guest

    I have a regex that needs multiline flag. Some where I read I can pass
    multiline flag in regex string itself without using re.compile. If
    anybody have any idea about how to do that please reply.
    samba, May 23, 2009
    #1
    1. Advertising

  2. samba

    Tim Chase Guest

    > I have a regex that needs multiline flag. Some where I read I
    > can pass multiline flag in regex string itself without using
    > re.compile. If anybody have any idea about how to do that
    > please reply.



    As detailed at [1],

    """
    (?iLmsux)

    (One or more letters from the set 'i', 'L', 'm', 's', 'u', 'x'.)
    The group matches the empty string; the letters set the
    corresponding flags: re.I (ignore case), re.L (locale dependent),
    re.M (multi-line), re.S (dot matches all), re.U (Unicode
    dependent), and re.X (verbose), for the entire regular
    expression. (The flags are described in Module Contents.) This is
    useful if you wish to include the flags as part of the regular
    expression, instead of passing a flag argument to the compile()
    function.
    """

    So you should be able to insert "(?m)" at the beginning of your
    regexp to make it multiline.

    -tkc


    [1]
    http://docs.python.org/library/re.html
    Tim Chase, May 23, 2009
    #2
    1. Advertising

  3. samba

    MRAB Guest

    samba wrote:
    > I have a regex that needs multiline flag. Some where I read I can pass
    > multiline flag in regex string itself without using re.compile. If
    > anybody have any idea about how to do that please reply.


    Include "(?m)" in the regular expression for multiline matching. It's
    best to put it at the start.
    MRAB, May 23, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. krigare
    Replies:
    0
    Views:
    829
    krigare
    Dec 27, 2003
  2. =?Utf-8?B?Sm9obiBCYW5raGVhZA==?=

    Failed Complie due to locked DLL

    =?Utf-8?B?Sm9obiBCYW5raGVhZA==?=, Dec 30, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,956
    =?Utf-8?B?Q2hpbm1heQ==?=
    Jan 4, 2005
  3. Ben
    Replies:
    2
    Views:
    862
  4. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    1,968
    Lawrence D'Oliveiro
    May 20, 2011
  5. dale zhang
    Replies:
    8
    Views:
    406
    Tintin
    Nov 30, 2004
Loading...

Share This Page