I'm having a really weird problem with preg_replace here (and as far as I can remember, this isn't the first time I've seen this). I have an XML with an element with invalid structure (closing tag is missing the slash, breaks parser):    &lt;info&gt;  &lt;datetime&gt;2013.04.12 12:04:02&lt;/datetime&gt;  &lt;info&gt;    What I'm trying to do is this: $xml = preg_replace('/&lt;info&gt;.*&lt;info&gt;/iu', '', $xml) (because I don't actually need that element), but IT DOES NOT REPLACE. How do I make it work?
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}?
70874
Do you know any good tools for nicely formatting messy php code? Preferably a script for Aptana/Eclipse, but a standalone tool will do too.
74283
I was answering a question on Stack Overflow and required to use a trailing space in one of my code snippets.  I formatted it like so:  `&lt;a `   And it renders without the trailing space: &lt;a  Using the &lt;code&gt; tag does account for trailing spaces, though in my case it busts because of the &lt;. Here's my formatting with the &lt;code&gt; tag:  &lt;code&gt;&lt;a &lt;/code&gt;   Here's how it renders:  (Yes, you should see nothing there).  This is a pretty annoying bug. Can we get it fixed?
90937
I am making a regex expression in which I only want to match wrong tags like: &lt;p&gt; *some text here, some other tags may be here as well but no ending 'p' tag* &lt;/p&gt;   &lt;P&gt;Affectionately Inscribed &lt;/P&gt;&lt;P&gt;TO &lt;/P&gt;&lt;P&gt;HENRY BULLAR, &lt;/P&gt;&lt;P&gt;(of the western circuit)&lt;P&gt;PREFACE&lt;/P&gt;   In the above same text I want to get the result as  &lt;P&gt;(of the western circuit)&lt;P&gt; and nothing else should be captured. I'm using this but its not working:  &lt;P&gt;[^\(&lt;/P&gt;\)]*&lt;P&gt;   Please help.
89095
I need to match a space character in a PHP regular expression. Anyone got any ideas?  I mean like "gavin schulz", the space in between the two words. I am using a regular expression to make sure that I only allow letters, number and a space. But I'm not sure how to find the space. This is what I have right now:  $newtag = preg_replace("/[^a-zA-Z0-9s|]/", "", $tag);
33461
I have long recognized that any set of whitespace in an HTML file will only be displayed as a single space.  For instance, this:  &lt;p&gt;Hello.        Hello. Hello. Hello.                       Hello.&lt;/p&gt;   displays as:  Hello.        Hello. Hello. Hello.                       Hello.  This is perfectly fine, as if you need multiple spaces of pre-formatted text you can just use the &lt;pre&gt; tag.  But what is the reason?  More precisely, why is this in the specification for HTML?
19672
I have several identical elements with different attributes that I'm accessing with SimpleXML:  &lt;data&gt;     &lt;seg id="A1"/&gt;     &lt;seg id="A5"/&gt;     &lt;seg id="A12"/&gt;     &lt;seg id="A29"/&gt;     &lt;seg id="A30"/&gt; &lt;/data&gt;   I need to remove a specific seg element, with an id of "A12", how can I do this?  I've tried looping through the seg elements and unsetting the specific one, but this doesn't work, the elements remain.  foreach($doc-&gt;seg as $seg) {     if($seg['id'] == 'A12')     {         unset($seg);     } }
50605
How do I save user-entered line breaks from a &lt;textarea&gt; HTML element to a database?  It always removes the line breaks.
103139
How does one post XML in Stack Overflow?  I've tried using &lt;pre&gt; and backticks to no avail. I suppose that I could go through and try indent every line by four spaces but that would get really tedious really fast.  Is there any way to easily post XML in a question?  Edit:  URL of question:   I tried putting the XML inside &lt;code&gt; tags and that sliced and diced the XML in a very odd fashion.
8360
I would like to do the following: $find = &quot;start (.*) end&quot;; $replace = &quot;foo \1 bar&quot;;  $var = &quot;start middle end&quot;; $var =~ s/$find/$replace/;  I would expect $var to contain &quot;foo middle bar&quot;, but it does not work. Neither does: $replace = 'foo \1 bar';  Somehow I am missing something regarding the escaping.
92604
This works fine:  sed -i 's#    @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb   against a source of  @driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click   I am just left with:  'change_district')]").click`   but when I try to add a single quote at the end it fails:  sed -i 's#    @driver.find_element(:xpath, "//a\[contains(@href,\'##' temp_spec.rb  syntax error near unexpected token `('   I am using \' to escape the single quote.  Note that I am using a # as a delimiter instead of the normal / delimiter as there are /'s in the text.
76092
I need to add PHP tags surrounding a file. It's easy to append them using  find . -exec echo "?&gt;" &gt;&gt; '{}' \;   but how can I prepend the tag &lt;?php?
108151
I ran into a regression change in the post formatting engine . If you try to embed an image using the exclamation sign syntax ![foo][bar] and the paragraph starts with a &lt;p&gt; or &lt;hr&gt; tag, the image formatting code is shown as literal text, not as an image. Example: This image is in a bare paragraph and shows up:  This image is after a &lt;p&gt; tag and doesn't show up: ![(a hand-drawn red circle as a test image)][1] As a possible workaround, you can use an &lt;img&gt; tag:  I found this when I was writing .  The image embedded in the post , but .  This confused me thoroughly, because I was trying to edit a part of the post other than the image. Apparently , but it doesn't seem to be mentioned on Meta SE yet.
45764
I have a directory full of XML files that look like this, for which I want to change the value of the "offset" element number from 1 to some other number  $ cat my.xml       &lt;offset xmlns=""&gt;1&lt;/offset&gt;   I wrote various combinations of this sed command, but nothing I tried runs without an error.  I am pretty sure that I need to escape some of the characters, but those that I've tried always end in errors ("unexpected token", "unknown option", etc).  I also tried without the -e flag, since it really isn't an expression.  sed -i -e s/&lt;offset xmlns=""&gt;1&lt;/offset&gt;/&lt;offset xmlns=""&gt;99&lt;/offset&gt;/ *.xml   Any help would be appreciated.
14665
I've been looking for a simple regex for URLs, does anybody have one handy that works well?  I didn't find one with the zend framework validation classes and have seen several implementations.
24405
The tag  and meta-tag  syntax generate much nicer looking results than merely surrounding your tag with [square brackets].    However, they only work when you're talking about the site you're on.  On Area51, in Chat, and on Meta sites, this is frequently not the case, leading to attempts at syntax like [[tag:failure]](https://superuser.com/questions/tagged/failure), which produces:    Hmm, must be some subtle syntax thing:   : [tag:failure](https://superuser.com/questions/tagged/failure) []: [[tag:failure](https://superuser.com/questions/tagged/failure)] : [tag:[failure]((https://superuser.com/questions/tagged/failure))] : &lt;a href="https://superuser.com/questions/tagged/failure"&gt;[tag:failure]&lt;/a&gt; : [tag:failure][1] \n\n [1]: https://superuser.com/questions/tagged/failure : [more text is a [tag:failure] too](https://superuser.com/questions/tagged/failure)   I give up!  How can I create a link to a tag on another site with tag markdown?
15376
Have a look at   One of the bolds works, and the other one just turns up as ** in the actual post.  This is the string that isn't working: **x**ml n**ib**  Which renders as: xml nib