Regular Expressions

Oracle Database for Beginners Oracle Database Objects
11 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.63
List Price:  €92.34
You save:  €27.70
£55.44
List Price:  £79.20
You save:  £23.76
CA$95.39
List Price:  CA$136.28
You save:  CA$40.89
A$105.31
List Price:  A$150.46
You save:  A$45.14
S$94.41
List Price:  S$134.88
You save:  S$40.47
HK$546.48
List Price:  HK$780.72
You save:  HK$234.24
CHF 63.35
List Price:  CHF 90.51
You save:  CHF 27.15
NOK kr752.35
List Price:  NOK kr1,074.83
You save:  NOK kr322.48
DKK kr482.29
List Price:  DKK kr689.02
You save:  DKK kr206.72
NZ$115.40
List Price:  NZ$164.87
You save:  NZ$49.46
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,188.09
List Price:  ৳11,697.78
You save:  ৳3,509.68
₹5,844.32
List Price:  ₹8,349.40
You save:  ₹2,505.07
RM329.44
List Price:  RM470.65
You save:  RM141.21
₦106,069.84
List Price:  ₦151,534.84
You save:  ₦45,465
₨19,432.66
List Price:  ₨27,762.13
You save:  ₨8,329.47
฿2,557.57
List Price:  ฿3,653.83
You save:  ฿1,096.26
₺2,258.73
List Price:  ₺3,226.90
You save:  ₺968.16
B$359
List Price:  B$512.88
You save:  B$153.88
R1,287.23
List Price:  R1,838.99
You save:  R551.75
Лв126.41
List Price:  Лв180.60
You save:  Лв54.18
₩95,083
List Price:  ₩135,838.68
You save:  ₩40,755.68
₪258.36
List Price:  ₪369.10
You save:  ₪110.74
₱4,027.01
List Price:  ₱5,753.12
You save:  ₱1,726.10
¥10,906.36
List Price:  ¥15,581.18
You save:  ¥4,674.82
MX$1,179.09
List Price:  MX$1,684.49
You save:  MX$505.39
QR254.79
List Price:  QR364
You save:  QR109.21
P949.80
List Price:  P1,356.91
You save:  P407.11
KSh9,116.19
List Price:  KSh13,023.69
You save:  KSh3,907.50
E£3,278.15
List Price:  E£4,683.28
You save:  E£1,405.12
ብር4,011.90
List Price:  ብር5,731.54
You save:  ብር1,719.63
Kz58,559.69
List Price:  Kz83,660.29
You save:  Kz25,100.60
CLP$64,011.45
List Price:  CLP$91,448.85
You save:  CLP$27,437.40
CN¥505.41
List Price:  CN¥722.04
You save:  CN¥216.63
RD$4,086.68
List Price:  RD$5,838.37
You save:  RD$1,751.68
DA9,422.44
List Price:  DA13,461.21
You save:  DA4,038.76
FJ$156.72
List Price:  FJ$223.89
You save:  FJ$67.17
Q543.77
List Price:  Q776.85
You save:  Q233.07
GY$14,641.02
List Price:  GY$20,916.64
You save:  GY$6,275.62
ISK kr9,728.61
List Price:  ISK kr13,898.61
You save:  ISK kr4,170
DH700.19
List Price:  DH1,000.32
You save:  DH300.12
L1,241.04
List Price:  L1,772.99
You save:  L531.95
ден3,982.98
List Price:  ден5,690.21
You save:  ден1,707.23
MOP$563.11
List Price:  MOP$804.48
You save:  MOP$241.36
N$1,285.34
List Price:  N$1,836.29
You save:  N$550.94
C$2,571.34
List Price:  C$3,673.51
You save:  C$1,102.16
रु9,351.07
List Price:  रु13,359.25
You save:  रु4,008.17
S/260.45
List Price:  S/372.09
You save:  S/111.64
K271.10
List Price:  K387.31
You save:  K116.20
SAR262.46
List Price:  SAR374.97
You save:  SAR112.50
ZK1,748.19
List Price:  ZK2,497.53
You save:  ZK749.33
L321.68
List Price:  L459.56
You save:  L137.88
Kč1,601.24
List Price:  Kč2,287.58
You save:  Kč686.34
Ft24,952.05
List Price:  Ft35,647.32
You save:  Ft10,695.26
SEK kr754.74
List Price:  SEK kr1,078.25
You save:  SEK kr323.50
ARS$61,957.22
List Price:  ARS$88,514.10
You save:  ARS$26,556.88
Bs483.55
List Price:  Bs690.82
You save:  Bs207.26
COP$271,364.95
List Price:  COP$387,680.83
You save:  COP$116,315.88
₡35,852.12
List Price:  ₡51,219.51
You save:  ₡15,367.39
L1,726.61
List Price:  L2,466.70
You save:  L740.08
₲524,366.82
List Price:  ₲749,127.57
You save:  ₲224,760.74
$U2,698.07
List Price:  $U3,854.56
You save:  $U1,156.48
zł275.81
List Price:  zł394.04
You save:  zł118.22
Already have an account? Log In

Transcript

Hi, in this lesson, we understand how to use regular expressions in Oracle starting from Oracle 10 g we got support for regular expressions, we have four different functions dealing with regular expressions and one more was added subsequently, which is regular expression count. Regular Expression like is an enhanced version of our like operator. That means, it supports regular expression. And then regular expression in string substring and replace are similar to the string functions we have seen before. But these functions support regular expressions. But what is a regular expression?

Regular expression is a string that can have meta characters. And these meta characters specify what are we exactly looking for And if you see a few examples here, the first one says we are looking for any character in the given list. The list is consisting of ABC, so any character in that list will be a match to it. The next example shows not ABC. This is where I'm saying, I'm looking for anything other than ABC. Because the carrot symbol in square brackets is treated as not.

This is where we talk about a range of characters. And this is where we say the string should start with what is given after that. So in this case, the string should start with the digit and here the string should contain 10 digits. So this is where we are saying it should start with that it should end with that and in between, we need to have 10 days We can also specify minimum and maximum occurrences. So two comma four means minimum to maximum four. And another powerful concept is grouping.

We are grouping our expressions. This is group one, this is group two. We'll see some examples using regular expression related functions. The first function is regular expression like if the string is matching the pattern it returns true. We can also give match options. For example, if you gave I it means you want to ignore the case while you're comparing strings.

Let us say the first example. This is saying we are looking for employers where the first name is starting with STD ending with n. But in between, we can have either we are PGH So the pipe symbol says either this or that. So Stephen r Steven will be a match to this. This is how we form the regular expression. And you are using regular expression like to check whether the first name is a match to it. The second one is looking for street address where we have a desert at the beginning.

So, if the street address starts with a desert, it is a match. Let's go try them. So this is my first example when I run this, it is giving me all the names where we have st he in the beginning end at the end, in between you might have we are pch. The second example is looking for three desserts at the beginning. I just improvise date and I'm saying I'm looking for not one but two. DCs, there you are, you get all the street addresses where we have at least three visits?

Well, I can increase it to five or whatever I want. So if I say five, I will get less number of matches. In fact, I'm getting only one. Well, that's about it. The next regular expression function is in string, unlike like, it is not returning Boolean, it is returning the position of the match. So this is where I'm looking for the first alphabet in the street address.

And this is one way to say we are looking for an alphabet you can replace this with something like small a to small Jade capital A to capital jet, if you like, or you can give alpha in this way. So we are looking for the first alpha beta In string returns the position. The second example is looking for at least two deserts. So wherever we have two deserts, it's going to return the position of that particular location. These are examples for regular expression in string and substring is extracting whatever is matching the regular expression. So here we are looking for in the street address one or more digits.

So wherever in the street address you find one or more digits, you extract that, but this is slightly more complex. We are looking for a space followed by one or more because this plus means one or more. But what we are not looking for is desert ends. space. So start with the space, take all the characters other than deserts and spaces. And that will be the match.

So we are using not g zero to nine and space. Let's check how it works. So this is my first example, where I'm looking for regular expression in string. And using this to find out the position of first alphabet, and when you run you get something like this. So in this the first alphabet is we that is in sixth position. And similarly regular expression substring.

And here, let's take this first, I'm looking for all the desserts. So whatever desserts we have, we get that of course, if you have multiple numbers, it will give you only the first number. It's not going to take the remaining and the next day What is a regular expression replace, this can be used to replace a string with another string, but the first one is a regular expression. So, wherever you have a dot, I want that to be replaced it with hyphens. But this backslash before.is needed because.is itself a meta character. But in this case, I want to treat a.as a literal not as a special character.

And I'm using place just to indicate in case you have more than one dot, even all those dots are to be replaced with a hyphen. So if you go and run this, we replace all the occurrences of dots in the string with hyphen. And this is another example just to demonstrate how we can replace one or more diseases. with nine, so wherever you have a desert, replace that with the nine. So 515 all of them are replaced with the nine. And this is pretty powerful.

We are using grouping concept. So let's understand this. I'm using two groups here. The first group is looking for one or more desserts at the beginning of the string. Then it is looking for a dot, then it is looking for zero or more characters, and this.is treated as the literal dot, but this.is treated as a special character. It means it's a match to any character.

And I'm looking for two sets. The first set is one or more desserts. The second set is any set of characters. And this is represented as a backslash one first group This is represented as backslash two. Now I'm saying replace the original string with the new string, where you put the first group first, followed by hyphen, followed by second group in parenthesis. Well, let's run this to see how exactly it works.

Now there is our first number, and it is picking up these three desserts that becomes the first group, then it is putting hyphen, and anything after this dot, the rest of that is going to be second group, and that is placed in parentheses. This is our second group. So we can use grouping concept and select multiple values using multiple patterns like this. And this is a very useful function. It's like replays but it supports regular expression. So We can precisely select what we want.

The last function is regular expression count, which is just counting how many times the given pattern is found. And this is going to tell you how many times you have four or more alphabets in the street address. So in this case, it is finding three occurrences of string with four or more characters. Whereas in this way found only one color is the only match to it. So those are the options, regular expression substring to extract the string. Regular Expression replace is replacing one string with another count is counting.

So in this lesson, we understood what is regular expression and how to use those five functions related to regular expressions. That's it for now. I'll catch you in In the next lesson

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.