I have something like this in a file testtt:   {It captures this! } // question: 2572410  name: Question 2  ::Question 2::[html] Is it going to be -40 tomorrow?  { It can't capture this!!! why? }   when I do:  grep -o '{\([^}]*\)}' testttt   It can't capture the multi-line braces. Any help to modify it in way that it could capture both would be apppreciated!  PS. I have also tested the given solution from:  and it gives the following error:   grep: unescaped ^ or $ not supported with -Pz   You can find the text file of the output and file contents
36910
To be precise  Some text begin Some text goes here. end Some more text   and I want to extract entire block that starts from "begin" till "end".  with awk we can do like awk '/begin/,/end/' text.  How to do with grep?
10097
Does Java have a built-in way to escape arbitrary text so that it can be included in a regular expression? For example, if my users enter "$5", I'd like to match that exactly rather than a "5" after the end of input.
10243
I'm quite confused about the following regular expressions I found in a shell script:  ${0##*/} ${0%/*}   How do they work?
83894
I have a file containing a a large number of lines, each of which contains a bunch of numbers which are separated by spaces. I process this data in a pipe in some way, and then I want to collapse the multiple lines into a single line of all the numbers separated by spaces.  Is there a standard command-line utility I can use to do this? It seems like most line-by-line utilities won't mess with the newlines...
44642
Is there an issue with sed and new line character? I have a file test.txt with the following contents    aaaaa   bbbbb   ccccc   ddddd     The following does not work: sed -r -i 's/\n/,/g' test.txt    I know that I can use tr for this but my question is why it seems not possible with sed.     If this is a side effect of processing the file line by line I would be interested in why this happens. I think grep removes new lines. Does sed do the same?
4412
The Python docs say:     re.MULTILINE: When specified, the pattern character '^' matches at the beginning of the string and at the beginning of each line (immediately following each newline)... By default, '^' matches only at the beginning of the string...   So what's going on when I get the following unexpected result?  &gt;&gt;&gt; import re &gt;&gt;&gt; s = """// The quick brown fox. ... // Jumped over the lazy dog.""" &gt;&gt;&gt; re.sub('^//', '', s, re.MULTILINE) ' The quick brown fox.\n// Jumped over the lazy dog.'
74420
So pulling open a file with cat and then using grep to get matching lines only gets me so far when I am working with the particular log set that I am dealing with. It need a way to match lines to a pattern, but only to return the portion of the line after the match. The portion before and after the match will consistently vary. I have played with using sed or awk, but have not been able to figure out how to filter the line to either delete the part before the match, or just return the part after the match, either will work. This is an example of a line that I need to filter:  2011-11-07T05:37:43-08:00 &lt;0.4&gt; isi-udb5-ash4-1(id1) /boot/kernel.amd64/kernel: [gmp_info.c:1758](pid 40370="kt: gmp-drive-updat")(tid=100872) new group: &lt;15,1773&gt;: { 1:0-25,27-34,37-38, 2:0-33,35-36, 3:0-35, 4:0-9,11-14,16-32,34-38, 5:0-35, 6:0-15,17-36, 7:0-16,18-36, 8:0-14,16-32,34-36, 9:0-10,12-36, 10-11:0-35, 12:0-5,7-30,32-35, 13-19:0-35, 20:0,2-35, down: 8:15, soft_failed: 1:27, 8:15, stalled: 12:6,31, 20:1 }   The portion I need is everything after "stalled".  The background behind this is that I can find out how often something stalls:  cat messages | grep stalled | wc -l   What I need to do is find out how many times a certain node has stalled (indicated by the portion before each colon after "stalled". If I just grep for that (ie 20:) it may return lines that have soft fails, but no stalls, which doesn't help me. I need to filter only the stalled portion so I can then grep for a specific node out of those that have stalled.  For all intents and purposes, this is a freebsd system with standard GNU core utils, but I cannot install anything extra to assist.
51242
When I use the following, I get a result as expected:  $ echo {8..10} 8 9 10   How can I use this brace expansion in an easy way, to get the following output?   $ echo {8..10} 08 09 10   I now that this may be obtained using seq (didn't try), but that is not what I am looking for.  Useful info may be that I am restricted to this bash version. (If you have a zsh solution, but no bash solution, please share as well)  $ bash -version GNU bash, version 3.2.51(1)-release (x86_64-suse-linux-gnu)
68162
doesn't seem to work  The next example would delete everything between "ONE" and "TWO:"   #!/bin/sh sed ' /ONE/ { # append a line     N # search for TWO on the second line      /\n.*TWO/ { # found it - now edit making one line         s/ONE.*\n.*TWO/ONE TWO/     } }' file   i was expecting to delete everything between ONE and TWO.i tried with file where file contains.  [user5@mailserver ~]$ cat file ONE hello TWO   but the output come like   [user5@mailserver ~]$ ./test ONE hello TWO   I was expecting ONE TWO I am trying to make it correct but not able to do.
55851
I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be. For example, matching the beginning of a word works only if it is enclosed within quotes.  user@host:~/Desktop$ grep -E '\&lt;H' test Hello World user@host:~/Desktop$ grep -E \&lt;H test   [test contains the string Hello World]  But matching end and beginning of file works without dollar:  user@host:~/Desktop$ egrep d$ test Hello World   Why is it so? And what is the rule?
61276
Today, once again, the  came to my attention and I have decided to try to  using XeLaTeX. The result is far from perfect, worse even than Chrome's rendering.  Is there a way I can improve the result? Is XeLaTeX and LuaLaTeX incapable of handling the Ponny?  :  \documentclass[]{article} \usepackage{lmodern} \usepackage{amssymb,amsmath} \usepackage{ifxetex,ifluatex} \usepackage{fontspec} \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} \IfFileExists{upquote.sty}{\usepackage{upquote}}{} \IfFileExists{microtype.sty}{\usepackage{microtype}}{} \usepackage[normalem]{ulem} \setmainfont{Doulos SIL}  \title{html - RegEx match open tags except XHTML self-contained tags - Stack Overflow} \date{} \author{StackOverflow}  \begin{document} \maketitle  Rege̿̔̉x-based HTML parsers are the cancer that is killing StackOverflow \emph{it is too late it is too late we cannot be saved} the trangession of a chi͡ld ensures regex will consume all living tissue (except for HTML which it cannot, as previously prophesied) \emph{dear lord help us how can anyone survive this scourge} using regex to parse HTML has doomed humanity to an eternity of dread torture and security holes \emph{using rege}x as a tool to process HTML establishes a brea\emph{ch between this world} and the dread realm of c͒ͪo͛ͫrrupt entities (like SGML entities, but \emph{more corrupt) a mere glimp}se of the world of reg​\textbf{ex parsers for HTML will ins}​tantly transport a p\emph{rogrammer's consciousness i}nto a w\emph{orl}d of ceaseless screaming, he comes\sout{, the pestilent sl}ithy regex-infection wil​\textbf{l devour your HT}​ML parser, application and existence for all time like Visual Basic only worse \emph{he comes he com}es \emph{do not fi}​ght h\textbf{e com̡e̶s, ̕h̵i}​s un̨ho͞ly radiańcé de\emph{stro҉ying all enli̍̈́̂̈́ghtenment, HTML tags \textbf{lea͠ki̧n͘g fr̶ǫm ̡yo​͟ur eye͢s̸ ̛l̕ik͏e liq}​uid p}ain, the song of re̸gular exp​re\sout{ssion parsing} will exti\emph{​nguish the voices of mor​\textbf{tal man from the sp}​here I can see it can you see ̲͚̖͔̙î̩́t̲͎̩̱͔́̋̀ it is beautiful t​}he f\texttt{inal snuf}fing o\emph{f the lie​\textbf{s of Man ALL IS LOŚ͖̩͇̗̪̏̈́T A}}\textbf{LL I​S L}OST th\emph{e pon̷y he come}s he c̶̮om\sout{es he co}\textbf{\sout{me}s t\emph{he} ich​}or permeat\emph{es al}l MY FAC\emph{E MY FACE ᵒh god n\textbf{o NO NOO̼}}\textbf{O​O N}Θ stop t\emph{he an​*̶͑̾̾​̅ͫ͏̙̤g͇̫͛͆̾ͫ̑͆l͖͉̗̩̳̟̍ͫͥͨ}e̠̅s\texttt{ ͎a̧͈͖r̽̾̈́͒͑e} n\textbf{​ot rè̑ͧ̌aͨl̘̝̙̃ͤ͂̾̆ ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ T}O͇̹̺ͅƝ̴ȳ̳ TH̘\textbf{Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝}S̨̥̫͎̭ͯ̿̔̀ͅ  \end{document}   UPDATE  Using the Doulos SIL font gets me something closer to what Firefox renders but still far from perfect.
117087
I want to search all files in the current directory and below for the substring $form['#node']. So, I have tried, initially:  grep -R "\$form\[\\\\'" . and grep -R "\$form\[\'" .  But it returns no results. However,   grep -R "\$form\[" returns plenty of results, as there are instances of entries such as $form['#id'] or $form['#node'] in the files. Is there any reason why adding the escaped single quote causes an issue? I can't seem to find any clear indication of exactly how to escape a single quote in this case.  I need to check that my escaped characters are working as intended in this scenario.
32406
Technically, any odd number of backslashes, as described in .  &gt;&gt;&gt; r'\'   File "&lt;stdin&gt;", line 1     r'\'        ^ SyntaxError: EOL while scanning string literal &gt;&gt;&gt; r'\\' '\\\\' &gt;&gt;&gt; r'\\\'   File "&lt;stdin&gt;", line 1     r'\\\'          ^ SyntaxError: EOL while scanning string literal   It seems like the parser could just treat backslashes in raw strings as regular characters (isn't that what raw strings are all about?), but I'm probably missing something obvious.
66513
Is there a way to debug a regular expression in Python? And I'm not referring to the process of trying and trying till they work :)  Here is how regexes can be debugged in Perl:   use re 'debug';  my $str = "GET http://some-site.com HTTP/1.1"; if($str =~/get\s+(\S+)/i) {     print "MATCH:$1\n"; }   The code above produces the following output on my computer when ran:   Compiling REx "get\s+(\S+)" Final program:    1: EXACTF  (3)    3: PLUS (5)    4:   SPACE (0)    5: OPEN1 (7)    7:   PLUS (9)    8:     NSPACE (0)    9: CLOSE1 (11)   11: END (0) stclass EXACTF  minlen 5 Matching REx "get\s+(\S+)" against "GET http://some-site.com HTTP/1.1" Matching stclass EXACTF  against "GET http://some-site.com HTTP/1.1" (33 chars)    0           |  1:EXACTF (3)    3        |  3:PLUS(5)                                   SPACE can match 1 times out of 2147483647...    4       |  5:  OPEN1(7)    4       |  7:  PLUS(9)                                     NSPACE can match 20 times out of 2147483647...   24       |  9:    CLOSE1(11)   24       | 11:    END(0) Match successful! MATCH:http://some-site.com Freeing REx: "get\s+(\S+)"
72890
Is there any use for the unescaped ^ in (La)TeX, when not in math mode? If not, I couldn't see why it's necessary to escape it.
50297
I've noticed that man pages and other documents formatted by Unix utilities often use double backticks `` followed by double single quotes '' to wrap quoted phrases instead of the double quote character ". Single quotes are similarly replaced. Why is this?  Here are a couple examples, from the man page for grep:   To find all occurrences of the pattern `.Pp' at the beginning of a line:         $ grep '^\.Pp' myfile   The apostrophes ensure the entire expression is evaluated by grep instead  of by the user's shell.  The caret `^' matches the null string at the  beginning of a line, and the `\' escapes the `.', which would otherwise match  any character.   The grep utility is compliant with the IEEE Std 1003.1-2008 (``POSIX.1'')  specification.
94270
The command that I have prints out two of the lines whenever FW_6.0.0 is found, below is the code:  grep -oP 'FW_6.0.0, (.*)$' file   Below is the output, both has the same value of FW_6.0.0  FW_6.0.0, SUCCESS FW_6.0.0, OK   I would like to match two words, that is FW_6.0.0 and SUCCESS that can be found on the same line so that it prints this out:  FW_6.0.0, SUCCESS and eliminates FW_6.0.0, OK