M
M
Michael Compass2021-07-28 20:53:30
Regular Expressions
Michael Compass, 2021-07-28 20:53:30

How to remove chunks in a text with a regex?

There is a line with the text:

random text 1***trash2***y6f dhy 1 month ago 14 minutes, 29 seconds 3,620 name***trash3***random text 1","random text 2***trash2***pot 5aq 3 months ago 9 minutes, 9 seconds 226,629 name***trash3***random text 2","random text 3***trash2***uan 4fp 5 months ago 26 minutes 506,950 name***trash3***random text 3"


I want to remove what I highlighted in yellow and blue.
61018e562ee84134495764.jpeg

Question/problem:
I wrote a regular expression to remove what is yellow: ***trash3***+([\s\S]+)"+
But it removes all the data from the first to the last match found in the string..... in fact, leaving only the beginning and end of the entire string. But it is necessary to delete each found piece.

If it is not clear, then I will explain in more detail:

Yellow is what is between name and the quote "

How I want to implement it:
In the text, using JS is looking for these pieces with a regular expression:
***trash3***random text 1
***trash3***random text 2
***trash3***random text 3

and replace it with "emptiness".

that is, remove***trash3***and any random text immediately following it up to the closing quote (do not remove the quote).
random text 1 is some kind of random sentence consisting of several words.
Please note that the same random text comes before ***trash2***, but we do not delete it.

I also want to remove this random text:
y6f dhy
pot 5aq
uan 4fp
Which comes between ***trash2***and цифрой пробел и временным названием. Like 2 year, 27 years, 1 day, 6 days... and so on.

Highlighted in blue is what is between ***trash2***and any of these values:
{цифра} minutes
{цифра} minute
{цифра} day
{цифра} days
{цифра} weeks
{цифра} week
{цифра} hours
{цифра} hour
{цифра} years
{цифра} year
{цифра} months
{цифра} month


But most likely this is already the next regular season, because in my case, "cleaning" can be divided "into 2 times .... 2 iterations".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kedavr13, 2021-07-28
@kedavr13

(?<=\*\*\*trash2\*\*\*)(\w+\s+\w+)+|((\*\*\*trash3\*\*\*)(\w+\s+\ w)+")

V
Viktor Taran, 2021-07-28
@shambler81

tyts yellow
tyts blue
still blue so to speak creative interpretation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question