Regular expressions are used to search/replace expressions in a text, file etc. There are two parts: 1. Data in which string to be searched 2. String to be searched in data Regular expression mainly consists of 1. literal characters 2. Meta characters Examples example string : Once there lived a great king who was very kind and great worrier and greater than any other king of his times. To search for a word great, regular expression could be just great But if we have to search for great and greater the regular expression would be great(er)? or greate?r?. Here regular expression consists of literals and metacharacters. ? is a metacharacter which means zero or more existence of character preceding ? List of metacharacters
Examples: Once there lived a great king. ^(once)(?: )(th.*)(?: )(liv.*) will create grouping of matches. (?: are neglected in group counts) here groups created are 1. once 2. there 3. lived a great king |