Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Problem with multiline regex

Last post 09-04-2008, 11:06 AM by prometheuzz. 5 replies.
Sort Posts: Previous Next
  •  09-04-2008, 6:18 AM 45934

    Problem with multiline regex

    Hi, I'm trying to comment some statements from a database sql dump.

     

    I have som data like this:

    --

    --
    -- Role Membership
    --

    EXEC sp_addrolemember 'aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess', 'User'
    GO

    EXEC sp_addrolemember 'aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess', 'User'
    GO


    --
    -- Definition for user  :
    --

     

     

    So I get this: .*?--\n-- Role Membership\n--\n(.*?) selecting the first block

    I try to selec the  end with this: .*?--\n-- Role Membership\n--\n(.*?)\n--\n but it doesn't work.

     What am I doing wrong ?

  •  09-04-2008, 9:21 AM 45946 in reply to 45934

    Re: Problem with multiline regex

    palpu:
    ...

    I try to selec the  end with this: .*?--\n-- Role Membership\n--\n(.*?)\n--\n but it doesn't work.

     What am I doing wrong ?

    There are two new lines: so it's not --\n-- Role Membership\n--\n(.*?)\n but --\n-- Role Membership\n--\n\n(.*?)\n

    Also, if you want the . (dot) to match new lines as well, you need to tell your regex engine that: consult the API docs for your regex-tool/language/library, or tell us what tool/language/library you're using.

  •  09-04-2008, 9:52 AM 45950 in reply to 45946

    Re: Problem with multiline regex

    I'm using Ruby, and i use /m switch for multiline.

    Here is my expression : http://www.rubular.com/regexes/1053

    So, with your tip I manage to get what I want, but, how can I select al the content I want, "--"  being the limit, like in the link, but without having that last "--" in the match ?

     

    Thank you.

     

  •  09-04-2008, 9:59 AM 45951 in reply to 45950

    Re: Problem with multiline regex

    palpu:

    I'm using Ruby, and i use /m switch for multiline.

    Here is my expression : http://www.rubular.com/regexes/1053

    So, with your tip I manage to get what I want, but, how can I select al the content I want, "--"  being the limit, like in the link, but without having that last "--" in the match ?

     

    Thank you.

     

     

    Note that multi-line and dot-all are two different things. Dot-all is usually depicted with a 's' flag.

    Could you post what you're trying to extract from the example from your original post? That is still a bit unclear to me.

    Thanks.

  •  09-04-2008, 10:13 AM 45952 in reply to 45951

    Re: Problem with multiline regex

    Don't bother, I got it.

    Thank you !!!

  •  09-04-2008, 11:06 AM 45954 in reply to 45952

    Re: Problem with multiline regex

    Good to hear that!
View as RSS news feed in XML