How to regex this
-
Hello, Why
\\begin\{verbatimtab\}[\n.]*\\end\{verbatimtab\}
does not match
\begin{verbatimtab}
10 56
3 235
\end{verbatimtab}Any help appreciated,
Greetings - Jacek
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.
-
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.
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
-
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
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, PeterSoftware rusts. Simon Stephenson, ca 1994.
-
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, PeterSoftware rusts. Simon Stephenson, ca 1994.
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
-
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, PeterSoftware rusts. Simon Stephenson, ca 1994.
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
-
Hello, Why
\\begin\{verbatimtab\}[\n.]*\\end\{verbatimtab\}
does not match
\begin{verbatimtab}
10 56
3 235
\end{verbatimtab}Any help appreciated,
Greetings - Jacek
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:
- use
[\s\S]
to match any character, independent of singleline or multiline setting - use lazy match
*?
to allow multiple such groups to be matched individually
Cheers Andi
- use
-
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:
- use
[\s\S]
to match any character, independent of singleline or multiline setting - use lazy match
*?
to allow multiple such groups to be matched individually
Cheers Andi
- use