1
00:00:00,240 --> 00:00:06,840
Hi, welcome back to a new section in this section, you will learn to use regular expressions.

2
00:00:07,740 --> 00:00:14,330
So in this lecture, I'll explain you what regular expressions or first thing you should know is that

3
00:00:14,550 --> 00:00:22,110
regular expressions are use when you are dealing with text and when you're dealing with text.

4
00:00:22,530 --> 00:00:32,280
A good tool to use is a Jupyter notebook style environment, such as Jupiter Lab, which is a local

5
00:00:32,580 --> 00:00:36,690
solution or cloud based solution such as deep notes or Google.

6
00:00:36,690 --> 00:00:40,380
Call that I'm using deep notes in my case.

7
00:00:40,950 --> 00:00:48,620
So feel free to use any Jupiter notebook, or you can also use your own ideas, such as visual studio

8
00:00:48,630 --> 00:00:51,180
codes or by charm or Apple.

9
00:00:51,570 --> 00:00:59,910
So any idea with do, but I suggest you use Jupiter notebooks such as the wonks I'm using on deep notes.

10
00:01:00,090 --> 00:01:02,130
So if you want to use deep nodes, go to Duplo.

11
00:01:02,130 --> 00:01:08,490
That's com creates a free account and then go to new projects and you create a new Jupiter notebook.

12
00:01:11,490 --> 00:01:14,280
Then I'll give a name to my new notebook.

13
00:01:14,610 --> 00:01:21,810
I'll change it from ontitled pilot project to regular expressions.

14
00:01:22,440 --> 00:01:24,180
Press answers to change the name.

15
00:01:24,730 --> 00:01:26,520
And so now we have this notebook.

16
00:01:26,520 --> 00:01:28,980
You can simply run codes here.

17
00:01:29,160 --> 00:01:30,950
So just this is a sale.

18
00:01:30,960 --> 00:01:32,310
This is where we write codes.

19
00:01:32,520 --> 00:01:38,220
So print hello, execute with control, enter or command.

20
00:01:38,220 --> 00:01:38,610
Enter.

21
00:01:39,150 --> 00:01:40,090
And you get the offers.

22
00:01:40,540 --> 00:01:42,210
You're going to add some more codes here.

23
00:01:43,020 --> 00:01:43,470
Print.

24
00:01:45,900 --> 00:01:47,130
Hello again.

25
00:01:47,490 --> 00:01:48,960
Press command answer and on.

26
00:01:49,410 --> 00:01:53,670
Now back to regular expressions, what are regular expressions?

27
00:01:54,000 --> 00:02:03,150
Well, regular expressions basically are a set of characters, special characters that we write in Python.

28
00:02:03,600 --> 00:02:05,670
For example, a.

29
00:02:08,440 --> 00:02:21,310
Dash, that means any lowercase letter between A and set dot means any possible character zero to nine

30
00:02:21,310 --> 00:02:23,110
means any possible number and so on.

31
00:02:23,680 --> 00:02:30,670
So by giving these special characters, you are searching in a string for text patterns.

32
00:02:31,240 --> 00:02:32,560
Let me give you an example.

33
00:02:33,040 --> 00:02:41,230
Let's suppose we have some text file in our current directory here, and we want to process those files.

34
00:02:41,920 --> 00:02:49,000
As you know from the previous section or on file and folder operations, you could get a list of file

35
00:02:49,000 --> 00:02:53,680
names using the path dot ITR to methods.

36
00:02:53,890 --> 00:03:02,470
So that should give you something like file names, a list basically, which contains all the file names,

37
00:03:02,650 --> 00:03:06,310
which could be something like Nov 12 dot

38
00:03:08,860 --> 00:03:12,850
November 14 Dot Sixty.

39
00:03:14,530 --> 00:03:25,420
Perhaps Oct. four, October 17, that you could have Nov 22, the TSA unsworn, so we could have a thousand

40
00:03:25,420 --> 00:03:35,410
files now what if your task was to extract only the files that have a particular name pattern?

41
00:03:35,590 --> 00:03:45,190
For example, you only warned the files from the 1st of November to the 20th of November.

42
00:03:46,800 --> 00:03:54,420
So in that case, in our small example here, you would have to extract this file name that but not

43
00:03:54,500 --> 00:03:55,380
these two.

44
00:03:55,890 --> 00:04:05,460
So you want to automate the way to extract only those files that have the file name related to 1st of

45
00:04:05,460 --> 00:04:08,820
November, up to the 20th of November.

46
00:04:09,210 --> 00:04:12,690
In that case, you have to use regular expressions.

47
00:04:12,690 --> 00:04:18,839
You have to create a pattern using your regular expressions, so a set of special characters.

48
00:04:19,800 --> 00:04:23,400
So by creating that pattern, you are instructing Python.

49
00:04:23,670 --> 00:04:31,050
You are giving instructions to extract only those file names that have a pattern, such as, for example,

50
00:04:31,050 --> 00:04:41,100
that we want to see start with no, then have a dash and then have a number from one to 20.

51
00:04:41,400 --> 00:04:42,830
So that's the idea.

52
00:04:42,840 --> 00:04:49,740
That's what we want to do in our minds, but we want to translate that into this set of characters and

53
00:04:49,740 --> 00:04:51,090
then filter those out.

54
00:04:51,210 --> 00:04:53,970
So that's what we're going to do in the next video.

55
00:04:54,900 --> 00:05:00,170
So that is a list of strings, but you could also have just one single string.

56
00:05:01,620 --> 00:05:06,780
For example, it could be just some simple text, such as, Hi, there you hear.

57
00:05:06,930 --> 00:05:17,130
And then you have perhaps some email addresses such as example, the dot example, dot com, some more

58
00:05:17,130 --> 00:05:19,140
text here and there.

59
00:05:19,440 --> 00:05:21,660
And then perhaps you have another email address.

60
00:05:22,440 --> 00:05:25,530
Another ATS example?

61
00:05:26,040 --> 00:05:28,050
Dot the E!

62
00:05:29,280 --> 00:05:29,820
And so on.

63
00:05:29,970 --> 00:05:38,070
So in this other example, your task could be to extract the email addresses only from these big piece

64
00:05:38,070 --> 00:05:38,700
of text.

65
00:05:39,140 --> 00:05:49,230
Again, you'd have to write a regular expression where you would see half any number of characters van,

66
00:05:49,230 --> 00:05:50,550
followed by ET.

67
00:05:51,210 --> 00:05:59,160
So that's the distinct part of an email address or email addresses have this at symbol and then followed

68
00:05:59,160 --> 00:06:01,650
by another set of characters.

69
00:06:01,830 --> 00:06:09,120
Any number of characters, followed by a dot and followed by another set of characters which could become

70
00:06:09,630 --> 00:06:15,510
the E etc. So the final output would be a list of all the email addresses.

71
00:06:16,350 --> 00:06:20,670
So those are two typical examples of using regular expressions.

72
00:06:21,210 --> 00:06:31,050
You have probably also encountered regular expressions in programs such as what processors say, Microsoft

73
00:06:31,050 --> 00:06:36,660
Office, where there is a built in tool that allows you to write a regular expression.

74
00:06:37,320 --> 00:06:44,940
So a regular expression is not exclusive to Python or regular expressions are basically a language.

75
00:06:46,080 --> 00:06:49,410
You can avoid those expressions in other programs as well.

76
00:06:49,530 --> 00:06:53,610
Microsoft Office as an example also Python.

77
00:06:53,880 --> 00:07:01,980
However, writing regular expressions inside Python takes you to another level because you can do everything

78
00:07:01,980 --> 00:07:02,640
with Python.

79
00:07:02,790 --> 00:07:06,900
You can combine the search with another operation off of that.

80
00:07:06,910 --> 00:07:11,970
So, for example, here you want to extract this email addresses and then send an email to all those

81
00:07:11,970 --> 00:07:12,750
email addresses.

82
00:07:13,020 --> 00:07:17,160
So Python allows you to do that because you have libraries for everything.

83
00:07:17,160 --> 00:07:23,160
So you have libraries for sending out emails, and perhaps you want to see these into a seasoned file.

84
00:07:23,730 --> 00:07:27,030
You have pandas, the pandas library for events as well.

85
00:07:27,690 --> 00:07:34,580
So Microsoft Word is just a tiny, tiny dot compared to Python towards Python can do.

86
00:07:35,940 --> 00:07:44,020
So I hope that gives you some insights on what regular expressions are, but you will see them in practice,

87
00:07:44,020 --> 00:07:45,000
certainly in the next video.

88
00:07:45,210 --> 00:07:53,040
We will be working on this email example from the email addresses, from this piece of text.

89
00:07:53,370 --> 00:07:54,450
So see you in the next video.

