Skip to content
Advertisement

How do i extract some particular words from each line?

The text file has many lines of these sort , i want to extract the words after /videos till .mp4 and the very last number ( shown in bold ) and output each filtered line in a separate file

JavaScript

Lets say for example the text file content is ..

JavaScript

The output should be

JavaScript

Advertisement

Answer

You may try the below regex:

JavaScript

Explanation of the above regex:

.* – Matching everything before videos.

/videos/ – Matching videos literally.

(.*?mp4) – Represents a capturing group lazily matching everything before mp4.

.*? – Greedily matches everything before the occurrence of digits.

(d+) – Represents second capturing group matching the numbers at the end as required by you.

You can find the demo of the above regex in here.


Pictorial representation

Command line implementation in linux:

JavaScript

You can find the sample implementation of the above command in here.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement