While reading the docs, I found out that the whole difference between re.match() and re.search() is that re.match() starts checking only from the beginning of the string.  &gt;&gt;&gt; import re &gt;&gt;&gt; a = 'abcde' &gt;&gt;&gt; re.match(r'b', a) &gt;&gt;&gt; re.search(r'b', a) &lt;_sre.SRE_Match object at 0xffe25c98&gt; &gt;&gt;&gt; re.search(r'^b', a) &gt;&gt;&gt;   Is there anything I am misunderstanding, or is there no difference at all between re.search('^' + pattern) and re.match(pattern)?  Is it a good practice to only use re.search()?
372
What is the difference between the search() and match() functions in the ?  I've read the  (), but I never seem to remember it.  I keep having to look it up and re-learn it.  I'm hoping that someone will answer it clearly with examples so that (perhaps) it will stick in my head.  Or at least I'll have a better place to return with my question and it will take less time to re-learn it.
123694
I want to search for string that have  [RT]"anything"D  which mean first character can either be R or T  and the next can be anything until D is appear what should I use is it "egrep"?
117030
"RE" means "recursively enumerable" and "R" means "recursive.  i am looking for the simplest solution- using a known languages such that do not demand another formal proof.
18421
What is the difference between \emph{...} and {\em ...}?  When to use each of them?
67376
I’m a newbie in Python. I’m learning regexes, but I need help here.  Here comes the HTML source:  &lt;a href="http://www.ptop.se" target="_blank"&gt;http://www.ptop.se&lt;/a&gt;   I’m trying to code a tool that only prints out http://ptop.se. Can you help me please?
123543
I wonder if there is an easy way to check if two strings match by excluding certain characters in the strings. See example below.  I can easily write such a method by writing a regular expression to find the "wild card" characters, and replace them with a common character. Then compare the two strings str1 and str2. I am not looking for such implementations, but like to know whether there are any .Net framework classes that can take care of this. Seems like a common need, but I couldn't find any such method.  For example:  string str1 = "ABC-EFG";     string str2 = "ABC*EFG";   The two strings must be declared equal.  Thanks!
12451
In the Stack Overflow podcast #36 (), this opinion was expressed: Once you understand how easy it is to set up a state machine, you’ll never try to use a regular expression inappropriately ever again. I've done a bunch of searching.  I've found some academic papers and other complicated examples, but I'd like to find a simple example that would help me understand this process.  I use a lot of regular expressions, and I'd like to make sure I never use one &quot;inappropriately&quot; ever again.
65647
Pattern pattern = Pattern.compile("^[a-z]+$"); String string = "abc-def"; assertTrue( pattern.matcher(string).matches() ); // obviously fails   Is it possible to have the character class match a "-" ?
47023
Say I have the string "User Name:firstname.surname" contained in a larger string how can I use a regular expression to just get the firstname.surname part?  Every method i have tried returns the string "User Name:firstname.surname" then I have to do a string replace on "User Name:" to an empty string.  Could back references be of use here?  Edit:  The longer string could contain "Account Name: firstname.surname" hence why I want to match the "User Name:" part of the string aswell to just get that value.
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?
55229
I've been wondering, what is the difference between seek and search? When should one be preferred over the other?
9882
This is a generalization of the "string contains substring" problem to (more) arbitrary types.  Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it?   As a bonus, it should return the index of the element where the subsequence starts:  Example usage (Sequence in Sequence):  &gt;&gt;&gt; seq_in_seq([5,6],  [4,'a',3,5,6]) 3 &gt;&gt;&gt; seq_in_seq([5,7],  [4,'a',3,5,6]) -1 # or None, or whatever   So far, I just rely on brute force and it seems slow, ugly, and clumsy.
8877
I've seen lots of examples of making an entire regular expression case-insensitive.  What I'm wondering about is having just part of the expression be case-insensitive.  For example, let's say I have a string like this:  fooFOOfOoFoOBARBARbarbarbAr   What if I want to match all occurrences of "foo" regardless of case but I only want to match the upper-case "BAR"s?  The ideal solution would be something that works across regex flavors but I'm interested in hearing language-specific ones as well (Thanks )  Edit  The link Espo provided was very helpful.  There's a good example in there about turning modifiers on and off within the expression.  For my contrived example, I can do something like this:  (?i)foo*(?-i)|BAR   which makes the match case-insensitive for just the foo portion of the match.  That seemed to work in most regex implementations except Javascript, Python, and a few others (as Espo mentioned).    The big ones that I was wondering about (Perl, PHP, .NET) all support inline mode changes.
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?
106681
The new search function allows quoted queries that include punctuation, and this is fantastic, most of the time. However, the search considers the punctuation as part of the word itself, so searches for "a test" will not show results containing a test,, a test., or a test?. The reverse is also true.  Is this the intended behavior ? &lt;--(space added so that behavior will show in results.)  It seems that the logical way to do fix this (while maintaining character search) is for queries with punctuation to match results with punctuation, while queries without punctuation to match either with and without.    Example:  vs     A more practical example is described in Arjan's answer below.
9182
Just recently,  question was posted. Here's the body of the question:     Write a function called highlight() that prompts the user for a string. Your code should ensure that the string is all lower case. Next, prompt the user for a smaller 'substring' of one or more characters. Then replace every occurrence of the substring in the first string with an upper case. Finally, report to the user how many changes were made (i.e., how many occurrences of the substring there were).      What would a script for this be?   This is basically a "do my homework for me" style question. In the past, I would have voted to close this question for lacking minimal understanding and moved on. However, it looks like this close reason was removed, and I'm having difficulty figuring out which alternative to use (if at all).  Here were some of the close reasons I was considering, and ultimately decided against since they didn't seem to precisely match:   Duplicate of    I sort of doubt there exists a precise duplicate of this question -- the question is a fairly specific request for some code. I could maybe link to a duplicate question that answers a part of the original (for example, checking if the string is lowercase), but it wouldn't answer every aspect of the problem. Problem that can't be reproduced/typographical error    This sort of matches, since it asks the user to produce a SSCCEE, but doesn't really match since there isn't even a problem to begin with (and closing a question because I couldn't "reproduce" a non-existent problem feels a bit silly to me) Unclear what you're asking    It's pretty obvious what the user is asking -- I could produce a 5 line script in about 20 seconds that precisely matches his spec. Too broad    The text for "Too broad" states that "There are either too many possible answers, or good answers would be too long for this format". This doesn't apply to this question -- once again, the answer I could give would be fairly short and would closely resemble solutions other people would give.   So, what should I do here? Am I misunderstanding how the close reasons should now be used? Should I use the "other" close reason and explain that the OP should have put in more effort? Should I simply downvote, perhaps leave a comment, and move on? Or is the new policy to embrace these kinds of questions and just post an answer?
24166
It took me a while to word this best.  Problem 1:  Is there a way to find lines in a text file that have the same string at the beginning and the same strings at the end?   Beginning and end strings not necessarily equal to each other.  Text between the two strings is not consistant in number of characters or number of hyphens.  A hyphen is in between notable strings (which I added to my large text file).  For example:  File:    AAAAA-tjhut-ghyut-FILE1.txt   BBB-fhuj-dnbhg-frt76-FILE2.txt   AAAAA-ghtujukr-hgute7gr-xhyutt-FILE1.txt   AAAAA-VGYT-4d7tt-xhyutt-FILE1.txt   CCCC-fjuk-dryy-fhuj-FILE3.txt   Lines to detect:    AAAAA-tjhut-ghyut-FILE1.txt   AAAAA-ghtujukr-hgute7gr-xhyutt-FILE1.txt   AAAAA-VGYT-4d7tt-xhyutt-FILE1.txt   Problem 2:  Is there a way to remove all but one of the lines containing the duplicate strings at the beginning and end from above?  Before:    AAAAA-tjhut-ghyut-FILE1.txt   AAAAA-ghtujukr-hgute7gr-xhyutt-FILE1.txt   AAAAA-VGYT-4d7tt-xhyutt-FILE1.txt   After:    AAAAA-tjhut-ghyut-FILE1.txt   Big thanks for any advice.  Note: I think using the occurances of the first hyphen and last hyphen can be used to locate the duplicate strings.