0
4.7kviews
Give applications of regular expressions
1 Answer
1
64views
  • A regular expression is a sequence of symbols and characters expressing a string or pattern to be searched for within a longer piece of text.

  • A regular expression provides an easier representation of a pattern

  • For example, a regular expression of the form 00* represents the first 0 is mandatory and there can be zero of more occurrence of the second zero, making it easier to write and represent.

Applications:

The applications of regular expressions can range from file search in Windows to validation of user inputs in javascript.

1. Windows file search:

  • In Windows, if a user wishes to search or display a list of all doc files, user will simply enter “.*doc” in the search area(now replaced by a simple “.doc”), which evaluates as a regular expression.

2. For Validation in javascript:

  • In javascript, if a user enters an email id and the system is required to check if validations for the email id field have been met or not, the developer would have to match the user input to a number of substrings.

  • This part however, is simplified because of regular expressions, wherein we specify a pattern and all the strings falling in the criteria of that pattern will be matched with the email id field.

  • A regular expression of the type “/^[A-Z]+@[A-Z]+.com/” would be needed to simplify the developer’s job(Here, A-Z means a range of alphabets, + indicates 1 or more occurences of the same,’/^’ indicates start of regular expression and ‘/’ indicates end of regular expression

Please log in to add an answer.