. Answer the given 9 questions correctly.
. You get 10 points for every correct answer you give.
1 Which of the following matches regexp /a(ab)*a/
abababa
Regular expressions are specially encoded text strings used as patterns for matching sets of strings. They began to emerge in the 1940s as a way to describe regular languages, but they really began to show up in the programming world during the 1970s. The first place I could find them showing up was in the QED text editor written by Ken Thompson.
“A regular expression is a pattern which specifies a set of strings of characters; it is said to match certain strings.” —Ken Thompson
Regular expressions later became an important part of the tool suite that emerged from the Unix operating system—the ed, sed and vi (vim) editors, grep, AWK, among others. But the ways in which regular expressions were implemented were not always so regular.
Some text our prices. Lorem ipsum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
Each language has different rules for describing Regular Expressions. We are going to analyze it for JS.
Character | What does it do? | Example | Matches |
---|---|---|---|
^ | Matches beginning of line | ^abc | abc, abcdef.., abc123 |
$ | Matches end of line | abc$ | my:abc, 123abc, theabc |
. | Match any character | a.c | abc, asg, a2c |
| | OR operator | abc|xyz | abc or xyz |
(...) | Capture anything matched | (a)b(c) | Captures 'a' and 'c' |
(?:...) | Non-capturing group | (a)b(?:c) | Captures 'a' but only groups 'c' |
[...] | Matches anything contained in brackets | [abc] | a,b, or c |
[^...] | Matches anything not contained in brackets | [^abc] | xyz, 123, 1de |
[a-z] | Matches any characters between 'a' and 'z' | [b-z] | bc, mind, xyz |
{x} | The exact 'x' amount of times to match | (abc){2} | abcabc |
{x,} | Match 'x' amount of times or more | (abc){2,} | abcabc, abcabcabc |
{x,y} | Match between 'x' and 'y' times. | (a){2,4} | aa, aaa, aaaaa |
* | Greedy match that matches everything in place of the * | ab*c | abc, abbcc, abcdc |
+ | Matches character before + one or more times | a+c | ac, aac, aaac, |
? | Matches the character before the ? zero or one times. Also, used as a non-greedy match | ab?c | ac, abc |
\ | Escape the character after the backslash or create an escape sequence. | a\sc | a c |
Powered by hasan GULBABA