Regex Flashcards

1
Q

Regular expressions

A

A language independent approach to expressing patterns

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

Hierarchy of languages

A

Type 0: unrestricted grammars
Type 1: context-sensitive grammars
Type 2: context-free grammars
Type 3: regular grammars

Type 2 used in parsers
Type 3 used in regular expressions and lexical analyzers

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

Grep

A

Global regular expression print

  • arg 1: a regex
  • arg 2: a set of files where grep will try to find strings matching regex
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A

Start with

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

[^]

A

Not in set

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

.

A

Any char

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

-w

A

Contains that specific word

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

-i

A

Case insensitive

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

$

A

Ends with

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

a*

A

Zero or more reps of ‘a’

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

a+

A

one or more reps of ‘a’

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

a?

A

Zero or one rep of ‘a’

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

a{5}

A

Exactly 5 reps of ‘a’

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

a{3,7}

A

3 to 7 reps of ‘a’

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

[abc]

A

Any one char in the set

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

a|b

A

Match ‘a’ or ‘b’

17
Q

()

A

Group a component of symbols in the regex

18
Q

\

A

Escape any meta symbol

19
Q

\d

A

Any decimal digit

20
Q

\w

A

Any alphanumeric char

21
Q

\s

A

Any white space char

22
Q

\b

A

Empty string at a word boundary

23
Q

\D

A

Match any non-digit char

24
Q

\W

A

Match any non-alphanumeric char

25
Q

\S

A

Match any non-white spice char

26
Q

\B

A

Empty string not at a word boundary

27
Q

\number

A

Matches text of group number

28
Q

re.match()

A

(string, pattern)

Return address

29
Q

re.compile()

A

Can use to reuse patterns

Helps to gain speed

30
Q

Word boundary

A

The first letter that starts a given word

31
Q

re.search()

A

Provides us with index (gives first index of first match

  • returns none if not found
  • but r in front to look at the raw text