Requirement of grouping meta-characters

In many of the earlier challenges you have used parentheses as a literal character by escaping it. But now you will learn why it is a unique character and how to use it.

In the introductory chapter of the course in scenario 2, you were we discussed the supposition that you are a scientist working on DNA. Your boss provides you with DNA text “AAGCCTAAGCCTAGATGCGT” and asked you to replace the following pattern “AAGCCTAAGCCT”. Because you now know the repetition characters, you can think of a solution.RegEx that looks like /A{2}GC{2}TA{2}GC{2}T/. This RegEx will match the following pattern in the given text.

But wait! What if a DNA string contains thousands characters. And what if the matching pattern is a hundred times longer than the present one? You are not going to write it a hundred times. When you observe the RegEx that you have just written, you will find that you have copy-pasted two parts, “A{2}GC{2}T”. If you could apply the repeat character to the entire group, it would have looked a lot simpler. However, you are familiar with the repeat character, which only works on the previous elements. To solve the problem of repeating or capturing a group of characters, you must mention them inside the parentheses. The characters or expressions mentioned inside parentheses are considered a group. Parentheses are the representation of grouping characters. Anything mentioned within the parentheses ( ) is considered a group.

Get hands-on with 1200+ tech skills courses.