Regex Flashcards

1
Q

Write a regular expression without the use of | which would match all of the three email addresses below:

foo@demo.net
bar.bar@test.co.uk
foobar@aqa.org

A

(([A-Za-z0-9][.])?[A-Za-z0-9][@][A-Za-z0-9][.][A-Za-z]([.][A-Za-z]*)?)

Accept other solutions which work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain the difference between lazy and greedy matching.

A

Lazy matching will attempt to match the pattern using the least amount of characters possible, stopping as soon as it has matched the pattern.

Greedy will attempt to match the pattern as much as it can, it will continue looking for more matches to the pattern even after it has matched the pattern.

Answer is correct as long as the following is stated:

Greedy means match longest possible string.

Lazy means match shortest possible string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does . match in regex?

A

. will match any character except line breaks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does regex stand for?

A

Regular expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does \D match and give an example of when it could be used.

A

\D will match any character that is not a digit character (0-9).

It could be used to trim phone numbers of the extra jabber added to them when they were input by a user.
Any other example where it serves the purpose of finding non-digit characters is correct.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a regular expression which matches the following:

a. b.c
d. e.f
g. h.i

but not the following:

1.2.3
x.y.z
A.B.C

A

([a-i].[a-i].[a-i])

Any other expression which work are accepted.
Emphasis on escaping the ..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain the use of +.

A

Will match one or more of the preceding token. (Minimum of 1 match required)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following would this regular expression match?

([test]{1}[0-9]*)

1) test1
2) 111
3) 90
4) test
5) 9test

A

1

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write an expression which matches the following without the use of | or ..

+44 (987) 123 5555
+10 (999) 420 6860
+0 (44) 123 9999

A

(+[0-9]{1,2}\s(([0-9]{1,3}))\s[0-9]{1,3}\s[0-9]{4})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is tokenisation?

A

Extracting elements which constitute a format.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are some uses of regular expressions?

A
Password strength checker.
Basic translation engine.
Grammatical suggestion engine.
Compiler.
Spam checker.
Key word filtering/identification.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly