Python regex not finding match in first line of file I'm using Python to process a text file, line by line, using RegEx. The first line includes the pattern to be matched, but for some reason Python isn't matching it. If I add a blank line—and make no other changes—it matches that line.  Any thoughts on why this might be happening?  Here's the relevant code:  infile = open(filename, 'r') fulltext = infile.readlines()  pattern = r'{LO[^{]*}(.)\s(.*)' regex = re.compile(pattern)  for line in fulltext:   match = re.match(regex,line)   Here's that first line. Again, it matches when it's not the first line, so I don't see what the issue is.  {LO 1.1a}m Plain text here.
What is the difference between re.search and re.match? 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.
Suppose that $X_1,X_2,\ldots,X_n$ is a random sample from a distribution with probability function:  $$p_X(x)=\begin{cases} 1/2 &amp;x=-1,1 \\ 0 &amp; \text{otherwise} \end{cases}$$  Now if we define the average   $\bar{X}= \frac{1}{n} \sum X_i$, I need to show that that for an odd $n$ the probability function for $\bar{X}$ is:  $$p_{\bar{X}} (x)= \frac{\binom{n}{\frac{n}{2} (x+1)}}{2^n}$$ for $x=\pm 1/n,\pm 3/n,\ldots,\pm 1$, $0$ otherwise.    Since $P[\sum X_i=k] =P [\bar{X}=k/n ]$, I thought it would be easier to first derive the probability function for the sum. Since they are still $2^n$ n-tuples and each one is equilikely, I need to count the ones whose sum is $k$ for:  $k=\pm 1,\pm 3,\ldots \pm n-2,\pm n$ (since even numbers are not a feasible combination)  The problem here though is that I do not immediately recognize how I could count all these tuples. Could you please help me with this? If it is easier to proceed another way, I am of course all ears. Username and Password not recognized when logging into Minecraft I've allocated an "array" of mystruct of size n like this:  if (NULL == (p = calloc(sizeof(struct mystruct) * n,1))) {  /* handle error */ }   Later on, I only have access to p, and no longer have n. Is there a way to determine the length of the array given just the pointer p?  I figure it must be possible, since free(p) does just that. I know malloc() keeps track of how much memory it has allocated, and that's why it knows the length; perhaps there is a way to query for this information? Something like...  int length = askMallocLibraryHowMuchMemoryWasAlloced(p) / sizeof(mystruct)   I know I should just rework the code so that I know n, but I'd rather not if possible. Any ideas? I have a question about the corollary to theorem 5.12 in Rudin's Principles of Mathematical Analysis (page 108):  Suppose $f$ is a real differentiable function on $[a,b]$ and suppose $f'(a)&lt; \lambda &lt; f'(b)$ then there is a point $x \in (a,b)$ such that $f'(x) = \lambda$ Corollary: If $f$ is differentiable on $[a,b]$ then $f'$ cannot have any simple discontinuities on $[a,b]$.  Can someone help me to show how he uses the result in the &quot;main theorem&quot; in the corollary?  (There are two cases of simple discontinuities  $f(x+) = f(x-) \neq f(x)$ and $f(x +) \neq f(x-)$ Should I use exit() or just return statements in main()? Personally I favor the return statements because I feel it's like reading any other function and the flow control when I'm reading the code is smooth (in my opinion). And even if I want to refactor the main() function, having return seems like a better choice than exit().  Does exit() do anything special that return doesn't? Could we please be a bit nicer to new users? There is a distinct decline in the level of civility on all the sites here.  Some of this is due to new users coming in and posting spam and other nonsense, but the off-topic and downvote buttons are doing a pretty good job of keeping this under control. Unfortunately, a lot of this is coming from more experienced users, and the site's built-in moderation system does not (and probably cannot) handle this very well.  Folks are rushing to pound new users down with &quot;this belongs on meta!&quot;, &quot;this is off topic&quot;, &quot;this is a duplicate!&quot; and &quot;read the Help!&quot;. (Which is correct, but should be done nicer) All this, of course, is accompanied by a flurry of downvotes.  This is not very welcoming to new users who don't know about meta, the Help, or what counts as off-topic. Now I am not proposing that we just allow off-topic, meta, or duplicate questions.  However, I think we could be gentler in the way we express these sorts of things.  Explain what meta and the FAQ are and provide useful links.  Just using please and thank-you when asking folks to read the FAQ or post something on meta would be an improvement.  I also think we could rein in the downvoting a bit.  Not that we shouldn't vote stuff down, but unless a new user's post is clearly spam, voting it down to -1 or -2 should be sufficient to send a message without piling on. I like Stack Exchange and I want it to become a resource for everyone, not just an elitist site for high-rep users on the sites. My initial problem was that my computer wouldn't let me login to my account. It seems to shut down after I enter my password. I can login as a guest.  I found fixes but I can't remember / figure out my login for access after I hit Ctrl+Alt+F1 and most of the fixes for finding your login username depend on you having access to your account.  I thought the login was the name which appears on the screen when I start the computer normally, but this has not worked, is there another way to find out my username while being effectively locked out of my root-user profile?  I am also assuming that the password is the same one I always use.  Conversely, if the name which appears on the screen at startup and my normal password should have worked, is there another explanation for why I am not able to login on the black command screen. If I pass PHP variables with . in their names via $_GET PHP auto-replaces them with _ characters. For example:  &lt;?php echo "url is ".$_SERVER['REQUEST_URI']."&lt;p&gt;"; echo "x.y is ".$_GET['x.y'].".&lt;p&gt;"; echo "x_y is ".$_GET['x_y'].".&lt;p&gt;";   ... outputs the following:  url is /SpShipTool/php/testGetUrl.php?x.y=a.b x.y is . x_y is a.b.   ... my question is this: is there any way I can get this to stop? Cannot for the life of me figure out what I've done to deserve this  PHP version I'm running with is 5.2.4-2ubuntu5.3. How to cut the non-overlapping part of 2 shapes in Illustrator CS6 I have 2 shapes (see below) a circle and a shape of the US. I want to remove the part of the US that falls outside the circle. How is this possible?    Thanks Is string in array? What would be the best way to look in a string[] to see if it contains a element. This was my first shot at it. But perhaps there is something that I am overlooking. The array size will be no larger than 200 elements.  bool isStringInArray(string[] strArray, string key) {     for (int i = 0; i &lt;= strArray.Length - 1; i++)         if (strArray[i] == key)             return true;     return false; } When I parent an object to follow a path and animate it, I only get a linear mode animation and changing that in Grapth Editor to bezier doesn't work! How to do that? I'd like to get a notification when a question that I've voted to close (but isn't closed yet) is edited How do I disable the guest session? How do I disable the guest session in Ubuntu 11.10 or higher? I don't want people to be able to use my computer without using a password to log in! Variable amount recurring billing Hi i'm looking for a payment gateway that can do recurring billing that changes month to month.  Fogbugz do this, they charge based on how many active users there were that month. All of the APIs that i've found only let you set a fixed amount and it's difficult/impossible to vary the subscription amount month to month.  Has anyone come across any services that do this? How can I hide my code in visualforce page? Another simple series convergence question: $\sum\limits_{n=3}^\infty \frac1{n (\ln n)\ln(\ln n)}$ I'm being asked to determine if $\displaystyle\sum\limits_{n=3}^\infty \frac1{n (\ln n)\ln(\ln n)}$ converges. So, using Cauchy's Condensation Test, I reduced the problem to one of determining the convergence of $\displaystyle\sum\limits_{n=3}^\infty\frac 1{n\ln (n\ln 2)}$. Am I on the right path, and how do I proceed from here? I'd like to see the full How-To on how to use manual partitioning during Ubuntu installation. The existing guides (at least those I found here) cover only automatic part and leave untouched the manual part (or extremely short and contain no pictures).  I'd like to cover such situations:     If your disk contains other systems: Graphical interface for generating presentation slides Is there a good graphical interface, similar to PowerPoint or LibreOffice Impress, for generating presentation slides?  When writing documents I prefer to write my text and LaTeX-markups using a text-editor and not using a graphical tool like LyX. However, in the case of presentation slides I want to see the layout and to have the ability to immediately see what you get e.g. by moving a picture with arrow keys.  ADDITION: The background to my question is as follows. I have used PowerPoint for more than a decade and like to use a WYSIWYG tool when making presentation slides. However, I can not use PowerPoint on my current computer and I think the output from LibreOffice Impress is inferior. As a long-time user of LaTeX, I have considered using SliTeX or Beamer but unfortunately I do not like the way of working. The end result is of course superior, but I found it very time-consuming and tiresome to e.g. adjust the position and size of pictures. Cascading Drop down in SharePoint Online I'm trying to implement cascading drop down for list in SharePoint online  I have 3 different list with name Countries , States, cities.  and the master list Address in which I have Fields Country , State, City.  I'm trying to display Sates for selected country. and City for selected States in SharePoint Online list How do I prevent yum from updating a particular RPM? For certain reasons I have to keep a slightly older version of a particular RPM installed on my box (Fedora 11). The problem is that every time I do a package update yum (or one of its GUI equivalents) wants to update this RPM to the latest version, which is annoying - especially when I update it by mistake.  Is there a way to 'pin' this version so that yum knows to never try and update it?