Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing RegEX to match URL pattern, invalid quantifier?
    primarykey
    data
    text
    <p>I am trying to use RegEX to match a URL pattern. I found an answer here: <a href="https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-an-url">Check if a Javascript string is a url</a></p> <p>Which pointed me to here: <a href="http://forums.devshed.com/javascript-development-115/regexp-to-match-url-pattern-493764.html" rel="nofollow noreferrer">http://forums.devshed.com/javascript-development-115/regexp-to-match-url-pattern-493764.html</a></p> <p>Which gave me the following code(cut and pasted from devshed to here and to my script):</p> <pre><code>function ValidURL(str) { var pattern = new RegExp('^(https?:\/\/)?'+ // protocol '((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'+ // domain name '((\d{1,3}\.){3}\d{1,3}))'+ // OR ip (v4) address '(\:\d+)?(\/[-a-z\d%_.~+]*)*'+ // port and path '(\?[;&amp;a-z\d%_.~+=-]*)?'+ // query string '(\#[-a-z\d_]*)?$','i'); // fragment locater if(!pattern.test(str)) { alert("Please enter a valid URL."); return false; } else { return true; } } </code></pre> <p>When I attempt to use it in Firefox 4.0, Firebug 1.7.3 gives me an invalid quantifier error at:</p> <pre><code> '(\#[-a-z\d_]*)?$','i'); // fragment locater </code></pre> <p>Does anyone have an idea on what the issue might be?</p> <p>From other searches on invalid quantifier, I believe that * is an issue but not sure what it might be. The string in question that I am using the function on when it gives me the error is:</p> <pre><code>htp://localhost:1987/ </code></pre> <p><strong>ADDED COMMENT</strong> The fix suggested by agent-j at least removed the invalid quantifier issue. <em>thumbs up</em></p> <p>However, it doesn't like the sample url above when done correctly:</p> <pre><code> http://localhost:1987/ </code></pre> <p>The issue is with the port. When I remove the port #, it likes localhost.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload