I want to extract the last occurrence of a string from a long string where this string occurs one or more times. I've tried a few different look ahead expressions but haven't been able to figure this out.  The string is something like:     AAA|BBB|Teststring:21|ZZZ|Teststring:23|Test 50   I tried using something an expression like:     (?:Teststring:\d+.(Teststring:\d+).$)   This works for those cases where there are more than one occurrences of Teststring, but fails when there is only one. So it works in the above test example but will fail for the below string:     AAA|BBB|Teststring:21|ZZZ 10
262
I don't really understand regular expressions.  Can you explain them to me in an easy-to-follow manner?  If there are any online tools or books, could you also link to them?
10784
I have Apache logfile, access.log, how to count number of line occurrence in that file? for example the result of cut -f 7 -d ' ' | cut -d '?' -f 1 | tr '[:upper:]' '[:lower:]' is  a.php b.php a.php c.php d.php b.php a.php   the result that I want is:  3 a.php 2 b.php 1 d.php # order doesn't matter 1 c.php
30755
How can I check if a string ends with a particular character in JavaScript?  Example: I have a string   var str = "mystring#";   I want to know if that string is ending with #. How can I check it?   Is there a endsWith() method in JavaScript? One solution I have is take the length of the string and get the last character and check it.   Is this the best way or there is any other way?
64488
I am trying to parse url-encoded strings that are made up of key=value pairs separated by either &amp; or &amp;amp;.   The following will only match the first occurrence, breaking apart the keys and values into separate result elements:  var result = mystring.match(/(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/)   The results for the string '1111342=Adam%20Franco&amp;348572=Bob%20Jones' would be:  ['1111342', 'Adam%20Franco']   Using the global flag, 'g', will match all occurrences, but only return the fully matched sub-strings, not the separated keys and values:  var result = mystring.match(/(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/g)   The results for the string '1111342=Adam%20Franco&amp;348572=Bob%20Jones' would be:  ['1111342=Adam%20Franco', '&amp;348572=Bob%20Jones']   While I could split the string on &amp; and break apart each key/value pair individually, is there any way using JavaScript's regular expression support to match multiple occurrences of the pattern /(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/ similar to PHP's preg_match_all() function?  I'm aiming for some way to get results with the sub-matches separated like:  [['1111342', '348572'], ['Adam%20Franco', 'Bob%20Jones']]   or   [['1111342', 'Adam%20Franco'], ['348572', 'Bob%20Jones']]
16793
I have a multi line log entry format that I need to process.   The log looks something like this:   --START-- Device=B Data=asdfasdf Lorem=Ipsum --END-- --START-- Device=A Data=asdfasdf Lorem=Ipsum --END-- --START-- Device=B Data=asdfasdf --END-- --START-- Device=A Data=asdfasdf --END-- --START-- Device=B Data=asdfasdf --END-- --START-- Device=C Data=asdfasdf Lorem=Ipsum --END--   I want to print everything between --START-- and --END-- if a particular pattern is matched.   e.g:   Print all entries where Device=A  --START-- Device=A Data=asdfasdf Lorem=Ipsum --END-- --START-- Device=A Data=asdfasdf --END--   All I've been able to do so far is write:   sed -e -n '/--START--/,/--END--/p' &lt; input   Which effectively prints the input but I think I need to add {} to filter with N and then print if that condition matches.   I also think I'm completely lost.  Any idea on how to print multiple lines if a single line matches a condition?
5821
I need a Perl regular expression to match a string. I'm assuming only double-quoted strings, that a \" is a literal quote character and NOT the end of the string, and that a \ is a literal backslash character and should not escape a quote character. If it's not clear, some examples:  "\""    # string is 1 character long, contains dobule quote "\\"    # string is 1 character long, contains backslash "\\\""  # string is 2 characters long, contains backslash and double quote "\\\\"  # string is 2 characters long, contains two backslashes   I need a regular expression that can recognize all 4 of these possibilities, and all other simple variations on those possibilities, as valid strings. What I have now is:  /".*[^\\]"/   But that's not right - it won't match any of those except the first one. Can anyone give me a push in the right direction on how to handle this?
17881
I'm trying to retrieve the the matching lines from a file, however the file that has the "index" or list of matches to retrieve also has duplicate entries and I want to print out the duplicates as well.  Example:  File 1 (index file or list of strings to match)  abc tgf abc ggg aaa fff   File 2 (what I want to retrieve for each of the matches in file 1)  Fred   1   3   abc Amy    2   4   ggg Dan    5   6   tgf Mike   9   1   fff Steve  2   1   aaa   My desired result would be (order is not important, just that I match every line):  Fred   1   3   abc Dan    5   6   tgf Fred   1   3   abc Amy    2   4   ggg Steve  2   1   aaa Mike   9   1   fff   I'm familiar and have tried grep as follows, but it does not print the duplicate entries.  grep -Fwf file1.txt file2.txt  Fred   1   3   abc Amy    2   4   ggg Dan    5   6   tgf Mike   9   1   fff Steve  2   1   aaa
109177
Say a sequence $\{X_1, X_2,\ldots ,X_n\}$ is given, where $X_p$ is either one or zero ($0 &lt; p &lt; n$). How can I determine the number of strings, which do contain at least one occurrence of consequent $1$'s of length $k$ ($0 &lt; k &lt; n$).   For example, a string $\{1, 0, 1, 1, 1, 0\}$ is such a string for $n = 6$ and $k = 3$.   I have found an answer for arbitrary $n$ and $k = 2$, ($k = 1$ is trivial), but I need a more general answer for any natural number  $k$ smaller than $n$.
62549
I'm having a bit of trouble getting a Python regex to work when matching against text that spans multiple lines. The example text is ('\n' is a newline)  some Varying TEXT\n \n DSJFKDAFJKDAFJDSAKFJADSFLKDLAFKDSAF\n [more of the above, ending with a newline]\n [yep, there is a variable number of lines here]\n \n (repeat the above a few hundred times).   I'd like to capture two things: the 'some_Varying_TEXT' part, and all of the lines of uppercase text that comes two lines below it in one capture (i can strip out the newline characters later).  I've tried with a few approaches:  re.compile(r"^&gt;(\w+)$$([.$]+)^$", re.MULTILINE) # try to capture both parts re.compile(r"(^[^&gt;][\w\s]+)$", re.MULTILINE|re.DOTALL) # just textlines   and a lot of variations hereof with no luck. The last one seems to match the lines of text one by one, which is not what I really want. I can catch the first part, no problem, but I can't seem to catch the 4-5 lines of uppercase text. I'd like match.group(1) to be some&#95;Varying&#95;Text and group(2) to be line1+line2+line3+etc until the empty line is encountered.  If anyone's curious, its supposed to be a sequence of aminoacids that make up a protein.
69159
How can you find the number of occurrences of a particular character in a string using sql?  Example: I want to find the number of times the letter ‘d’ appears in this string.  declare @string varchar(100) select @string = 'sfdasadhfasjfdlsajflsadsadsdadsa'
41314
I am looking for a regular expression that finds all occurences of double characters in a text, a listing, etc. on the command line (Bash).  Main Question: Is there a simple way to look for sequences like aa, ll, ttttt, etc. where one defines a regular expression that looks for n occurences of the same character with? What I am looking for is achieving this on a very very basic level. On the command line. In a Linux Shell.  After quite some research I came to the following answers &ndash; and questions resulting from them, thus they just gave me a hint where the solution might be. But:  a) (e)grep and the backslash issue   grep 'a\{2\}' looks for aa egrep'a{2}' looks for aa   Question: Is the necessity of setting backlashes really bound to the command I use? If so, can anyone give me hint what else is to be taken into account when using (e)grep here?  b) I found  for my question, though it isn't exactly what I was looking for:  grep -E '(.)\1' filename looks for entries with the same character appearing more than once but doesn't ask how often. This is close to what I am looking for, but I still want to set a number of repeatings.  I probably should split this into two or more questions, but then I don't want to flood this awesome site here.   P.S.: Another question, possibly off topic but: is it in, inside, at or on the shell. And is on the command line correct?
16529
I want to determine whether a multi-line string ends with a line containing specified pattern.  These code failed, it doesn't match.  s=`echo hello &amp;&amp; echo world &amp;&amp; echo OK` [[ "$s" =~ 'OK$' ]] &amp;&amp; echo match
40669
I want to reverse a regular expression. I.e. given a regular expression, I want to produce any string that will match that regex.  I know how to do this from a theoretical computer science background using a finite state machine, but I just want to know if someone has already written a library to do this. :)  I'm using Python, so I'd like a Python library.  To reiterate, I only want one string that will match the regex. Things like "." or ".*" would make an infinite amount of strings match the regex, but I don't care about all options.  I'm willing for this library to only work on a certain subset of regex.
96053
Is there a formula or script that will match sub-strings from one column in another column and return the full value of the sub-string match? e.g.  Input  COL_a            COL_b name             201284_blah_year.ext address          407284_blah_name.xml journal          501283_blah_journal_entries.ott journal_entries  701284_blah_type.dat year             401184_blah_journal.ext type             301287_blah_address.txt   Desired output  COL_a            COL_b name             407284_blah_name.xml  address          301287_blah_address.txt journal          401184_blah_journal.ext  journal_entries  501283_blah_journal_entries.ott  year             201284_blah_year.ext  type             701284_blah_type.dat
92306
I have the following format in Excel and I am trying to extract the data between the characters:  First Last &lt;flastname@xxxx.com&gt;   I need to extract the email address between &lt; and > into its own cell  Thanks!
50428
I want to replace the first occurrence in a given string.   How can I accomplish this in .NET?
64545
I have a list of replacements like so:  search_and -&gt; replace big_boy -&gt; bb little_boy -&gt; lb good_dog -&gt; gd ...   I need to make replacements for the above, but at the same time avoid matching strings that are longer like these:  big_boys good_little_boy   I tried this:  sed -i -r "s/$(\W){search}(\W)/$\1{replacement}\2/g"   But the above does not work when the string ("good_dog" in this case) occurs at the end of a line like so:  Mary had a 'little_boy', good_little_boy, $big_boy, big_boys and good_dog  Mary had a 'lb', good_little_boy, $bb, big_boys and good_dog   And I doubt the above would work when the string occurs at the start of the line too. Is there a good way to do the search and replacement?