Another task with the Dome event can be like this split each new sentence to a separate line in the
paragraph text, a sentence can be assumed to be a string of text terminated with a period.
And actually, we have exactly the same text and paragraph, just like we did previously.
Now the question is how we can implement this task.
And actually, one might think, okay, we have, period.
We can simply split it by period.
Let's try this out.
First of all, I want to find here our paragraph with document quote a selector p just like we did previously.
And now here we can write paragraph dot inestimable equals paragraph dot image HTML.
And we want to split it with DOT.
And let's check what we will have in this case after we split it and we have an array of our strings,
we must join it back.
But in this case, we want to put here, first of all, DOD because we're joined in and by DOD.
But then we need a close tag for our and open tech for our own U.P.
In this case, were writing paragraphs for every single line and join is not applied to the last element.
This is why at the end we want to write plays and whoever must close our additional team.
Let's check the salt overload in the page.
And actually, it is working, but only partially.
Yes, it is working for the simple sentences, but it won't work for the sentences where we have two
or three dots, for example.
As you can see here, we have lines with one dot on it.
And this is exactly the problem, because here we split it just by one dot and this is Ron button.
Total, our logic is correct.
We can expect our STEM elements as you can see, they are prepped correctly, wispy and then were close
in our last picture.
So it is working, but split by a dot is not our case.
And actually, here were coming to regular expressions.
And this is some knowledge that you must learn, at least on the basic level, because you will use
it in a lot of cases when you are working, for example, with strings and to try and check regular
expression.
I highly recommend you to use the website at of dot com.
It is completely free.
You can find another websites, but here it is really nice to see what we will find.
And as you can see here, you can write a regular expression.
And here you can provide the text and check how it will work.
Also here on the right, you can set some flags, for example, multi-line global and so on.
As you can see, this is the regular expression that we want to write, and when I'm hovering on this
symbols, it will show you what exactly we are doing here.
So this is the beginning of regular expression and we are prepping regular expression, always with
two slashes.
So this left at the beginning and ended the end is just a start and end of the regular expression.
Now here inside we have Dot, but Dot is a special symbol inside regular expression.
This is why we must escape it with the backslash.
As you can see here, this is just matches a dot character.
Now here we have square brackets.
And as you can see, everything inside square brackets is negated set, which actually means this must
not be there.
And this current symbol is the start of our set.
And here we have dot and open tech.
In this case, we're looking only for a single dot, but not for several dots.
This is everything that we want to see here.
And as you can see here in our code, it is working correctly.
And now we have this matches on only with a single dot.
As you can see here, we have three dots button with the last two will be checked because we're interested
only in Dot one.
We don't have the second dot afterwards.
This is where we can copy paste this regular expression and just put it inside our split.
And here I must write less at the beginning and end at the end.
And this is our regular expression, and I totally understand if you don't get 100 percent what I'm
doing here because you must learn some basics of regular expressions first, but they're extremely important
for you if you're working with strings.
Now let's check in for this code is working.
So here I am.
Jump into our page and reload in it.
And now it is working correctly.
We made our split, and here, for example, three dots are still there and this is the single sentence.
And when we have a 1.0, then we simply consider the split and then we move this text on the next line.
And actually, regular expression knowledge is a little bit outside of JavaScript, but you will still
use it a lot.
But also, if you will learn regular expressions, you cannot use them in every single language because
in all languages, it is exactly the same.