Question: Study guide: Advanced regular expressions Advanced regular expressions commonly referred to as advanced regexes are used by developers to execute complicated pattern matching against strings.
Study guide: Advanced regular expressions
Advanced regular expressionscommonly referred to as advanced regexesare used by developers to execute complicated pattern matching against strings. In this reading, you will learn about some of the common examples of advanced regular expressions.
Alterations
An alteration matches any one of the alternatives separated by the pipe symbol. Lets look at an example:
rlocationLondonBerlinMadrid
This line of code will match the text string location is London, location is Berlin, or location is Madrid.
Matching only at the beginning or end
If you use the circumflex symbol also known as a caret symbol as the first character of your regex, it will match only if the pattern occurs at the start of the string. Alternatively, if you use the dollar sign symbol $ at the end of a regex, it will match only if the pattern occurs at the end. Lets look at an example:
rMy name is w
This line of code will match My name is Asha but not Hello. My name is Asha.
Character ranges
Character ranges can be used to match a single character against a set of possibilities. Lets look at a couple of examples:
rAZ This will match a single uppercase letter.
r$ This will match any of the digits zero through nine, or the dollar sign, hyphen, comma, or period.
The two examples above are often combined with the repetition qualifiers. Lets look at one more example:
r
This line of code will match a US phone number such as
Backreferences
A backreference is used when using resub to substitute the value of a capture group into the output. Lets look at an example:
resubrAZsw rMsA Weber and B Bellmas have joined the team.
This line of code will produce Ms Weber and Ms Bellmas have joined the team.
Lookahead
A lookahead matches a pattern only if its followed by another pattern. Lets look at an example:
If the regex was rTestdPassed and the string was TestPassed, TestPassed, TestFailed, TestPassed, TestFailed the output would be:
Test Test Test
Key takeaways
The types of advanced regular expressions explained in this reading are just some of the more commonly used ones by developers. They are beneficial in pattern matching, text manipulation, and data validation. For more information, check out the following link:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
