What are the approaches of extracting a query string with regular expressions?
Submitted by: AdministratorThere 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.
Submitted by:
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.
Submitted by:
Read Online JQuery Programmer Job Interview Questions And Answers
Top JQuery Programmer Questions
☺ | What are jQuery Selectors? Give some examples? |
☺ | How to get the direct parent of an element using jQuery? |
☺ | How to set the style property of an element using jQuery? |
☺ | How to get the height of an element using jQuery? |
☺ | Explain the common methods of sending a request to a server? |
Top Scripting language Categories
☺ | AngularJS Interview Questions. |
☺ | Ext-JS Interview Questions. |
☺ | Dojo Interview Questions. |
☺ | Expert Developer JavaScript Interview Questions. |
☺ | jQuery Mobile Interview Questions. |