I have a string like this  1) /* This is the Start for the Test : 1 */ 2) Lu8_Ret = GetStatus_1(); 3) Lu8_Ret = Lu8_Ret + 1; 4)/* This is the End for the Test : 1 */ 5) 6) /* This is the Start for the Test : 2 */ 7) Lu8_Ret = GetStatus_2(); 8) Lu8_Ret = Lu8_Ret + 1; 9) /* This is the End for the Test : 2 */ 10)  11) /* This is the Start for the Test : 1 */ 12) Lu8_Ret = GetStatus_1(); 13) /* This is the End for the Test : 1 */   By using following regular expression I am reading the content between the start and end comment lines  regex = r"This is the Start for the Test : 1(([\S\s])*) This is the End for the Test : 1" for match in re.finditer(newrx, content):     print(match.group(1))   But it's giving the content between the start comment of Test: 1 to last end comment of Test: 1(line number 2 to 12).  How to get the content as a separate group (from line 2-3 as one group and line 12 as another group)? (My program will take care of unwanted /* , */ )
3211
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM J0000010: Project name: E:\foo.pf J0000011: Job name: MBiek Direct Mail Test J0000020: Document 1 - Completed successfully  I'm trying to extract pieces from it using regex. In this case, I want to grab everything after Project Name up to the part where it says J0000011: (the 11 is going to be a different number every time). Here's the regex I've been playing with: Project name:\s+(.*)\s+J[0-9]{7}:  The problem is that it doesn't stop until it hits the J0000020: at the end. How do I make the regex stop at the first occurrence of J[0-9]{7}?
5132
Is there a quick way to find every match of a regular expression in Ruby? I've looked through the Regex object in the Ruby STL and searched on Google to no avail.
3017
I wrote a regular expression which works well in a certain program (grep, sed, awk, perl, python, ruby, ksh, bash, zsh, find, emacs, vi, vim, gedit, …). But when I use it in a different program (or on a different unix variant), it stops matching. Why?
20352
Is it possible to detect a valid regular expression with another regular expression?  If so please give example code below.
3909
Is there a way to achieve the equivalent of a  in javascript regular expressions?  I need to match a string that does not start with a specific set of characters.  It seems I am unable to find a regex that does this without failing if the matched part is found at the beginning of the string.  Negative lookbehinds seem to be the only answer, but javascript doesn't have one.  EDIT: This is the regex that I would like to work, but it doesn't:  (?&lt;!([abcdefg]))m  So it would match the 'm' in 'jim' or 'm', but not 'jam'
2940
How can I test if a RegEx matches a string exactly?  var r = /a/; r.test("a"); // returns true r.test("ba"); // returns true testExact(r, "ba"); // should return false testExact(r, "a"); // should return true
118631
A friend asked me this and I was stumped: Is there a way to craft a regular expression that matches a sequence of the same character? E.g.,  match on 'aaa', 'bbb', but not 'abc'?  m|\w{2,3}|    Wouldn't do the trick as it would match 'abc'.  m|a{2,3}|    Wouldn't do the trick as it wouldn't match 'bbb', 'ccc', etc.
108459
Are Python and JavaScript regular expression syntax identical?   If not, then:    What are the important differences between them Is there a python library that "implements" JavaScript regexps?
46012
I am trying to find all matches in a string that begins with | |.    I have tried: if ($line =~ m/^\\\|\s\\\|/) which didn't work.   Any ideas?
81623
I am writing a script, I want to check if the first line of the file matches a certain pattern and if it does then print out the file. How can I achieve this?  How do I check for pattern? Is there a way to check for pattern and based on the output do something..  EDIT: Please take a look at this question:   I want something like this, but none of them worked for me. I basically want to check if the first line matches a regex pattern or not and based on that print the lines of file.
118546
Is there a regular expression that matches valid regular expressions?   (I know there are several flavors of regexps. One would do.)
33653
I have a text in a text file, where I want everything that is between strings like \{{[} and {]}\} to be deleted - including these strings themselves.  These two string can lie on different lines as well as on the same line. In either case,  on the line on which the beginning \{{[} lies, I don't want the text before, i.e. left, of it to be deleted - and the same holds for the text after {]}\}.  Here is an example: Given a text file with the content   Bla Bla bla bla \{{[} more bla bla even more bla bla bla bla.   A lot of stuff might be here.  Bla bla {]}\} finally done.  Nonetheless, the \{{[} show {]}\} goes on.   the script should return another text file with the content  Bla Bla bla bla  finally done.  Nonetheless, the  goes on.   Unfortunately this simple-looking task turned out to be too difficult for me to do with sed. I'm happy with any solution in any language, as long as I don't have to install anything on my standard linux machine (C and some java is already installed).
62677
I am writing a Java utility which helps me to generate loads of data for performance testing.  It would be really cool to be able to specify a regex for Strings so that my generator spits out things which match this.  Is there something out there already baked which I can use to do this?  Or is there a library which gets me most of the way there?  Thanks
18554
I'm new to regular expressions and would appreciate your help.  I'm trying to put together an expression that will split the example string using all spaces that are not surrounded by single or double quotes. My last attempt looks like this: (?!") and isn't quite working. It's splitting on the space before the quote.  Example input:   This is a string that "will be" highlighted when your 'regular expression' matches something.   Desired output:  This is a string that will be highlighted when your regular expression matches something.   Note that "will be" and 'regular expression' retain the space between the words.
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.
66135
I need to take the multi-line output of a program, match a string, and return the previous line of all matches.  An example of the output of the program:  $ jack_lsp -p firewire_pcm:analog-1_out         properties: input,physical,terminal, firewire_pcm:analog-2_out         properties: input,physical,terminal, firewire_pcm:analog-1_in         properties: output,physical,terminal, firewire_pcm:analog-2_in         properties: output,physical,terminal, $   I need to match, for example, 'input', and return the previous line of all matches. So in the example, the expected output would be:  firewire_pcm:analog-1_out firewire_pcm:analog-2_out   Here is what I have, but it only returns the first match:  $ jack_lsp -p | grep -B1 input | head -1 firewire_pcm:analog-1_out $   What am I doing wrong?
1424
I have the string   a.b.c.d   I want to count the occurrences of '.' in an idiomatic way, preferably a one-liner.  (Previously I had expressed this constraint as "without a loop", in case you're wondering why everyone's trying to answer without using a loop).