JQuery Programmer Question: Download JQuery Programmer PDF

What are the approaches of extracting a query string with regular expressions?

Tweet Share WhatsApp

Answer:

There are two approaches of doing so:

1. String based approach : This is the simple way of extracting the information of a query string using the string-based replacement technique. This method makes use of the .replace() method to function.
For ex :
var data = string.replace("http://localhost/view.php?", "");

The above code works fine for the string based approach but has some flexibility issues. It cannot deal effectively with domain name and file name changes.

2. Regular expression approach : They are a powerful pattern matching tool available in modern programming languages. For the extraction of a query string a pattern would have to be used which looks for a question mark in the string. Once it does it returns everything after it. The regular expression in JS are delimited using the forward slashes at the end of an expression.

Download JQuery Programmer PDF Read All 201 JQuery Programmer Questions
Previous QuestionNext Question
Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?What is the difference between calling stop(true,true) and finish method?