Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. How to regex this

How to regex this

Scheduled Pinned Locked Moved Regular Expressions
regexhelptutorial
8 Posts 3 Posters 23 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lutoslaw
    wrote on last edited by
    #1

    Hello, Why

    \\begin\{verbatimtab\}[\n.]*\\end\{verbatimtab\}

    does not match

    \begin{verbatimtab}
    10 56
    3 235
    \end{verbatimtab}

    Any help appreciated,

    Greetings - Jacek

    P A 2 Replies Last reply
    0
    • L Lutoslaw

      Hello, Why

      \\begin\{verbatimtab\}[\n.]*\\end\{verbatimtab\}

      does not match

      \begin{verbatimtab}
      10 56
      3 235
      \end{verbatimtab}

      Any help appreciated,

      Greetings - Jacek

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      You generally need a modifier tacked on the end of the regex, or an extra parameter in the call to match or whatever to specify multiline input. I'm guessing your current call stops scanning at the first newline. Sorry I can't be more specific without knowing what regex engine/language/context you're using. Cheers, Peter

      Software rusts. Simon Stephenson, ca 1994.

      L 1 Reply Last reply
      0
      • P Peter_in_2780

        You generally need a modifier tacked on the end of the regex, or an extra parameter in the call to match or whatever to specify multiline input. I'm guessing your current call stops scanning at the first newline. Sorry I can't be more specific without knowing what regex engine/language/context you're using. Cheers, Peter

        Software rusts. Simon Stephenson, ca 1994.

        L Offline
        L Offline
        Lutoslaw
        wrote on last edited by
        #3

        Thanks for answering! I tried to mess around NL settings, but without success. Could you get it working here: http://www.regexplanet.com/simple/index.html[^]? I'll be fine then (hopefully). Ultimately, I want to use it in VS find/replace dialog (Notepad++ does not support NL in regex :( ).

        Greetings - Jacek

        P 1 Reply Last reply
        0
        • L Lutoslaw

          Thanks for answering! I tried to mess around NL settings, but without success. Could you get it working here: http://www.regexplanet.com/simple/index.html[^]? I'll be fine then (hopefully). Ultimately, I want to use it in VS find/replace dialog (Notepad++ does not support NL in regex :( ).

          Greetings - Jacek

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          I didn't look closely at the middle of your regex. :-O Your fragment [\n.]* matches any number of (newline or fullstop) Inside the square brackets, the fullstop is not a wildcard. That is probably not what you want. A simple .* is probably what you need if you are not interested in capturing the content, given that the multiline flag should take care of "any character" matching newline. Cheers, Peter

          Software rusts. Simon Stephenson, ca 1994.

          L 2 Replies Last reply
          0
          • P Peter_in_2780

            I didn't look closely at the middle of your regex. :-O Your fragment [\n.]* matches any number of (newline or fullstop) Inside the square brackets, the fullstop is not a wildcard. That is probably not what you want. A simple .* is probably what you need if you are not interested in capturing the content, given that the multiline flag should take care of "any character" matching newline. Cheers, Peter

            Software rusts. Simon Stephenson, ca 1994.

            L Offline
            L Offline
            Lutoslaw
            wrote on last edited by
            #5

            Peter_in_2780 wrote:

            Inside the square brackets, the fullstop is not a wildcard.

            Oh, that was too easy :mad: BUT, it would work if VS allowed to setup regex in a find/replace dialog. It is not possible though. However, the \n works. How to code that regex if . does not catch a new-line and it cannot be changed? (answer: code it yourself, but I would be nice if it wasn't necessary)

            Greetings - Jacek

            1 Reply Last reply
            0
            • P Peter_in_2780

              I didn't look closely at the middle of your regex. :-O Your fragment [\n.]* matches any number of (newline or fullstop) Inside the square brackets, the fullstop is not a wildcard. That is probably not what you want. A simple .* is probably what you need if you are not interested in capturing the content, given that the multiline flag should take care of "any character" matching newline. Cheers, Peter

              Software rusts. Simon Stephenson, ca 1994.

              L Offline
              L Offline
              Lutoslaw
              wrote on last edited by
              #6

              Huh, it's not very critical thing, but, unfortuantely, begun to like the research. I have tried just now:

              string replaced = Regex.Replace(all, @"\\begin\{verbatimtab\}.*\\end\{verbatimtab\}", (Match m) => (m.Value), RegexOptions.Singleline);

              The SingleLine mode specs: "Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character except \n)." Didn't work.

              Greetings - Jacek

              1 Reply Last reply
              0
              • L Lutoslaw

                Hello, Why

                \\begin\{verbatimtab\}[\n.]*\\end\{verbatimtab\}

                does not match

                \begin{verbatimtab}
                10 56
                3 235
                \end{verbatimtab}

                Any help appreciated,

                Greetings - Jacek

                A Offline
                A Offline
                Andreas Gieriet
                wrote on last edited by
                #7

                Is this solved? If not, and if you are talking about C# Regex, then the following will do:

                string p = @"\\begin\{verbatimtab\}[\s\S]*?\\end\{verbatimtab\}";
                Console.WriteLine("{0}", Regex.Match(str1, p).Success);

                The trick:

                1. use [\s\S] to match any character, independent of singleline or multiline setting
                2. use lazy match *? to allow multiple such groups to be matched individually

                Cheers Andi

                L 1 Reply Last reply
                0
                • A Andreas Gieriet

                  Is this solved? If not, and if you are talking about C# Regex, then the following will do:

                  string p = @"\\begin\{verbatimtab\}[\s\S]*?\\end\{verbatimtab\}";
                  Console.WriteLine("{0}", Regex.Match(str1, p).Success);

                  The trick:

                  1. use [\s\S] to match any character, independent of singleline or multiline setting
                  2. use lazy match *? to allow multiple such groups to be matched individually

                  Cheers Andi

                  L Offline
                  L Offline
                  Lutoslaw
                  wrote on last edited by
                  #8

                  The topic is pretty outdated -- I have done it manually for much less time than I had spent trying to build a proper regex ;P Thanks for a nice trick to ignore multiline settings, though. :thumbsup:

                  Greetings - Jacek

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups