I'm using regex (https?:\/\/.*\.(?:png|jpg|jpeg|gif)) to validate image url and it's working, but still some unwanted user could put a code like this in the image url: http://avatar/image'OR''='/someimage.jpg and I wonder if there is another regex can detect special character like ' and ;
73
If user input is inserted without modification into an SQL query, then the application becomes vulnerable to , like in the following example:  $unsafe_variable = $_POST['user_input'];   mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')");   That's because the user can input something like value'); DROP TABLE table;--, and the query becomes:  INSERT INTO `table` (`column`) VALUES('value'); DROP TABLE table;--')   What can be done to prevent this from happening?
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);
104262
I was writing some Unit tests last week for a piece of code that generated some SQL statements.  I was trying to figure out a regex to match SELECT, INSERT and UPDATE syntax so I could verify that my methods were generating valid SQL, and after 3-4 hours of searching and messing around with various regex editors I gave up.  I managed to get partial matches but because a section in quotes can contain any characters it quickly expands to match the whole statement.  Any help would be appreciated, I'm not very good with regular expressions but I'd like to learn more about them.  By the way it's C# RegEx that I'm after.  Clarification  I don't want to need access to a database as this is part of a Unit test and I don't wan't to have to maintain a database to test my code. which may live longer than the project.
9185
Just starting to explore the 'wonders' of regex.  Being someone who learns from trial and error, I'm really struggling because my trials are throwing up a disproportionate amount of errors...  My experiments are in PHP using ereg().  Anyway.  I work with first and last names separately but for now using the same regex.  So far I have:  ^[A-Z][a-zA-Z]+$     Any length string that starts with a capital and has only letters (capital or not) for the rest.  But where I fall apart is dealing with the special situations that can pretty much occur anywhere.   Hyphenated Names (Worthington-Smythe)   Names with Apostophies (D'Angelo)   Names with Spaces (Van der Humpton) - capitals in the middle which may or may not be required is way beyond my interest at this stage. Joint Names (Ben &amp; Jerry)   Maybe there's some other way a name can be that I'm no thinking of, but I suspect if I can get my head around this, I can add to it.  I'm pretty sure there will be instances where more than one of these situations comes up in one name.  So, I think the bottom line is to have my regex also accept a space, hyphens, ampersands and apostrophes - but not at the start or end of the name to be technically correct.
118713
I can insert an image like so:  ![Desc Text][1]     [1]: http://www.funnycatpix.com/_pics/What_Are_You_Doing522.jpg   I can also link to said image:  [![Desc Text][1]][1]     [1]: http://www.funnycatpix.com/_pics/What_Are_You_Doing522.jpg   And you can click the image to open in a new tab (useful for big images).  Can some markdown be added to do this? I'm thinking of this sort of syntax:  !![Desc Text][1]     [1]: http://www.funnycatpix.com/_pics/What_Are_You_Doing522.jpg   Double ! or maybe some other symbol combo.
91604
Recently a URL was posted on Ask Different that looked like this:   Why does it have the "?as=1" at the end of it? I understand that it is part of the workings of the website, but what is its purpose?
108524
I need a RegEx pattern for extracting all the properties of an image tag.  As we all know, there are lots of malformed HTML out there, so the pattern has to cover those possibilities.  I was looking at this solution  but it didn't quite get it all:  I come up something like:  (alt|title|src|height|width)\s*=\s*["'][\W\w]+?["']   Is there any possibilities I'll be missing or a more efficient simple pattern?  EDIT: Sorry, I will be more specific, I'm doing this using .NET so it's on the server side. I've already a list of img tags, now I just need to parse the properties.
73199
I have a need to replicate SOQL's LIKE behaviour in Apex:  The % wildcard matches zero or more characters The _ wildcard matches exactly one character Case insensitive  including for cases where characters that have special meaning in regular expressions are used e.g. ( and ). What code do I need?
18272
This is for .NET. IgnoreCase is set and MultiLine is NOT set.  Usually I'm decent at regex, maybe I'm running low on caffeine...  Users are allowed to enter HTML-encoded entities (&lt;lt;, &lt;amp;, etc.), and to use the following HTML tags:  u, i, b, h3, h4, br, a, img   Self-closing &lt;br/&gt; and &lt;img/&gt; are allowed, with or without the extra space, but are not required.  I want to:   Strip all starting and ending HTML tags other than those listed above.  Remove attributes from the remaining tags, except anchors can have an href.   My search pattern (replaced with an empty string) so far:  &lt;(?!i|b|h3|h4|a|img|/i|/b|/h3|/h4|/a|/img)[^&gt;]+&gt;   This seems to be stripping all but the start and end tags I want, but there are three problems:   Having to include the end tag version of each allowed tag is ugly. The attributes survive. Can this happen in a single replacement? Tags starting with the allowed tag names slip through. E.g., "&lt;abbrev&gt;" and "&lt;iframe&gt;".   The following suggested pattern does not strip out tags that have no attributes.  &lt;/?(?!i|b|h3|h4|a|img)\b[^&gt;]*&gt;   As mentioned below, "&gt;" is legal in an attribute value, but it's safe to say I won't support that. Also, there will be no CDATA blocks, etc. to worry about. Just a little HTML.  Loophole's answer is the best one so far, thanks! Here's his pattern (hoping the PRE works better for me):  static string SanitizeHtml(string html) {     string acceptable = "script|link|title";     string stringPattern = @"&lt;/?(?(?=" + acceptable + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:([""']?).*?\1?)?)*\s*/?&gt;";     return Regex.Replace(html, stringPattern, "sausage"); }   Some small tweaks I think could still be made to this answer:   I think this could be modified to capture simple HTML comments (those that do not themselves contain tags) by adding "!--" to the "acceptable" variable and making a small change to the end of the expression to allow for an optional trailing "\s--". I think this would break if there are multiple whitespace characters between attributes (example: heavily-formatted HTML with line breaks and tabs between attributes).   Edit 2009-07-23: Here's the final solution I went with (in VB.NET):   Dim AcceptableTags As String = "i|b|u|sup|sub|ol|ul|li|br|h2|h3|h4|h5|span|div|p|a|img|blockquote"  Dim WhiteListPattern As String = "&lt;/?(?(?=" &amp; AcceptableTags &amp; _       ")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:([""']?).*?\1?)?)*\s*/?&gt;"  html = Regex.Replace(html, WhiteListPattern, "", RegExOptions.Compiled)   The caveat is that the HREF attribute of A tags still gets scrubbed, which is not ideal.
38485
is handy, but is there a similar function in the .NET framework for ?  I'm looking for syntax like this:  Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")   which would return:  "http://MyUrl.com/Images/Image.jpg"
39060
Whenever I try to insert " or ' I have to validate it by space, otherwise strange things happen as with ' followed by an a becomes áinstead of just 'a, similar behaviour with double quotes. I find this annoying and want to disable it. How do I do that?
83873
Is it possible to do something like this?  var pattern = /some regex segment/ + /* comment here */     /another segment/;   Or do I have to use new RegExp() syntax and concatenate a string? I'd prefer to use the literal as the code is both more self-evident and concise.
43149
I did a search for A$, but a whole bunch of results containing "Å", "A's" and "as" were return, could not find one containing "A$":    Same thing for other special characters such as "#".
33382
Can a regular expression match whitespace or the start of a string?  I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.  &gt;&gt;&gt; import re &gt;&gt;&gt; text = u'GBP 5 Off when you spend GBP75.00'  &gt;&gt;&gt; re.sub(ur'GBP([\W\d])', ur'£\g&lt;1&gt;', text) # matches GBP with any prefix u'\xa3 5 Off when you spend \xa375.00'  &gt;&gt;&gt; re.sub(ur'^GBP([\W\d])', ur'£\g&lt;1&gt;', text) # matches at start only u'\xa3 5 Off when you spend GBP75.00'  &gt;&gt;&gt; re.sub(ur'(\W)GBP([\W\d])', ur'\g&lt;1&gt;£\g&lt;2&gt;', text) # matches whitespace prefix only u'GBP 5 Off when you spend \xa375.00'   Can I do both of the latter examples at the same time?
42663
I have an input String say Please go to http://stackoverflow.com. The url part of the String is detected and an anchor &lt;a href=""&gt;&lt;/a&gt; is automatically added by many browser/IDE/applications. So it becomes Please go to &lt;a href='http://stackoverflow.com'&gt;http://stackoverflow.com&lt;/a&gt;.  I need to do the same using Java.
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.
18267
The list of valid XML characters is well known, as defined by the spec it's:  #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]   My question is whether or not it's possible to make a PCRE regular expression for this (or its inverse) without actually hard-coding the codepoints, by using Unicode general categories. An inverse might be something like [\p{Cc}\p{Cs}\p{Cn}], except that improperly covers linefeeds and tabs and misses some other invalid characters.