I know there are already questions for validating links. But I'm very bad with regex, and I don't know how to validate a user input (in html) is equivalent to these URL:  http://www.domain.com/?p=123456abcde   or  http://www.domain.com/doc/123456abcde   I guess it's like this  /^(http://)(www)((\.[A-Z0-9][A-Z0-9_-]*).com/?p=((\.[A-Z0-9][A-Z0-9_-]*)   I need the regex or the two URL. Thanks
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.
2898
I'm trying to put together a comprehensive regex to validate phone numbers. Ideally it would handle international formats, but it must handle US formats, including the following:   1-234-567-8901 1-234-567-8901 x1234 1-234-567-8901 ext1234 1 (234) 567-8901 1.234.567.8901 1/234/567/8901 12345678901   I'll answer with my current attempt, but I'm hoping somebody has something better and/or more elegant.
10610
I have a url like   I need a javascript function to give me the 'th' value from that.  All my urls have the same format (2 letter filenames, with .html extension).  I want it to be a safe function, so if someone passes in an empty url it doesn't break.  I know how to check for length, but I should be checking for null to right?
97389
How do I add a link to a URL containing parentheses () (or &quot;round brackets&quot; by heathens)? For example:  The parentheses around &quot;VS.85&quot; causes it to look like this: Markdown: [IHtmlDocument2 reference](http://msdn.microsoft.com/en-us/library/aa752574(VS.85).aspx) Output renders as
2940
How can I test if a RegEx matches a string exactly?  var r = /a/; r.test("a"); // returns true r.test("ba"); // returns true testExact(r, "ba"); // should return false testExact(r, "a"); // should return true
108459
Are Python and JavaScript regular expression syntax identical?   If not, then:    What are the important differences between them Is there a python library that "implements" JavaScript regexps?
37476
What is the easiest way to match non-ASCII characters in a regex? I would like to match all words individually in an input string, but the language may not be English, so I will need to match things like ü, ö, ß, and ñ. Also, this is in Javascript/jQuery, so any solution will need to apply to that.
6354
It seems like every question on stackoverflow where the asker is using regex to grab some information from HTML will inevitably have an "answer" that says not to use regex to parse HTML.  Why not? I'm aware that there are quote-unquote "real" HTML parsers out there like , and I'm sure they're powerful and useful, but if you're just doing something simple, quick, or dirty, then why bother using something so complicated when a few regex statements will work just fine?  Moreover, is there just something fundamental that I don't understand about regex that makes them a bad choice for parsing in general?
123007
We have a high security application and we want to allow users to enter URLs that other users will see.  This introduces a high risk of XSS hacks - a user could potentially enter javascript that another user ends up executing. Since we hold sensitive data it's essential that this never happens.  What are the best practices in dealing with this? Is any security whitelist or escape pattern alone good enough?   Any advice on dealing with redirections ("this link goes outside our site" message on a warning page before following the link, for instance)  Is there an argument for not supporting user entered links at all?    Clarification:  Basically our users want to input:      stackoverflow.com   And have it output to another user:  &lt;a href="http://stackoverflow.com"&gt;stackoverflow.com&lt;/a&gt;   What I really worry about is them using this in a XSS hack. I.e. they input:     alert('hacked!');   So other users get this link:  &lt;a href="javascript:alert('hacked!');"&gt;stackoverflow.com&lt;/a&gt;   My example is just to explain the risk - I'm well aware that javascript and URLs are different things, but by letting them input the latter they may be able to execute the former.  You'd be amazed how many sites you can break with this trick - HTML is even worse. If they know to deal with links do they also know to sanitise &lt;iframe&gt;, &lt;img&gt; and clever CSS references?  I'm working in a high security environment - a single XSS hack could result in very high losses for us. I'm happy that I could produce a Regex (or use one of the excellent suggestions so far) that could exclude everything that I could think of, but would that be enough?
112080
I'm looking for the ultimate postal code and zip code regex. I'm looking for something that will cover most (hopefully all) of the world.
93853
How would you go about creating a random alpha-numeric string that matches a certain regular expression?  This is specifically for creating initial passwords that fulfill regular password requirements.
34828
I am having a home page where I can search on multiple tags. How should I construct the URL? Suppose I search for tag = test_1 and tag = test_2  Should I construct the url like   http://www.example.com/tag/test-1,test-2   or  http://www.example.com/tag/?tag=test-1,test-2   or  www.example.com/tag/test-1-test-2   or  any other option?  I know query params are generally ignored by search engines and I should not put comma in URL so according to it "www.example.com/tag/test-1-test-2" is best option but I am afraid that www.example.com/tag/test-1-test-2 and www.example.com/tag/test-2-test-1 will generate the same result.
67727
How can I get the value between quotes with an RegEx  for example I want to find all the parameters from the function test  &lt;html&gt;    test("bla");    print("foo");    test("moo"); &lt;/html&gt;   The result must be { "bla", "moo" }
118631
A friend asked me this and I was stumped: Is there a way to craft a regular expression that matches a sequence of the same character? E.g.,  match on 'aaa', 'bbb', but not 'abc'?  m|\w{2,3}|    Wouldn't do the trick as it would match 'abc'.  m|a{2,3}|    Wouldn't do the trick as it wouldn't match 'bbb', 'ccc', etc.
4663
This will surely be an easy one but it is really bugging me.   I have a script that reads in a webpage and uses  to parse it. From the soup I extract all the links as my final goal is to print out the link.contents.  All of the text that I am parsing is ASCII. I know that Python treats strings as unicode, and I am sure this is very handy, just of no use in my wee script.   Every time I go to print out a variable that holds 'String' I get [u'String'] printed to the screen. Is there a simple way of getting this back into just ascii or should I write a regex to strip it?
7509
I try to write a simple Markdown parser in JavaScript. Therefore I want to check for the [link content][link id] syntax. I use the following code:  data = data.replace( /\[(.*?)\][ ]*\[([0-9]+)\]/g, '&lt;a href="$2"&gt;$1&lt;/a&gt;' );   It works well, but now I want to do this with a RegExp object. So I set up the following bit of code:  var r = new RegExp( '\[(.*?)\][ ]*\[([0-9]+)\]', 'g' ); data = data.replace( r, '&lt;a href="$2"&gt;$1&lt;/a&gt;' );   But it doesn't work. It even says that my regular expression (which works since the first example does a good job) is invalid:     unmatched ) in regular expression   I think it must have to do with some RegExp-object peculiarities I am not aware of. What am I doing wrong and how can the problem be solved?
18973
I need to write a function that receives a string and a regex. I need to check if there is a match and return the start and end location of a match. (The regex was already compiled by qr//.)  The function might also receive a "global" flag and then I need to return the (start,end) pairs of all the matches.  I cannot change the regex, not even add () around it as the user might use () and \1. Maybe I can use (?:).  Example: given "ababab" and the regex qr/ab/, in the global case I need to get back 3 pairs of (start, end).