I
I
IlyaPrivolnov3332022-02-03 18:49:49
Regular Expressions
IlyaPrivolnov333, 2022-02-03 18:49:49

How to use a regular expression to find certain words in the text after a certain word?

"{\"to_email\":\\"task_id\":\"39a84a7b-b937-4901-90a5-eb19a9411e7e\",\"cc\":[],\"bcc\":[],\"to \":{\"loaded_data\":null,\"generators\":[],\"account_name\":\"taxi\"},\"external_contract_id\":\"2291177/21\",\" reason\":\"notify\"}}"

Text without spaces is given. How to use a regular expression to find certain words (debt, notify, another) if they come after the word reason? That is, if these words come before the word reason - they should not be, if they are after - they should.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2022-02-03
@Aetae

The correct answer is to use the built-in json parser of the language you are working with and not engage in perversions.
Shitty answer: or depending on how crooked your line is. It will fail without options if there are quotation marks in the searched word. /(?<="reason":")([^"]+)//(?<=\\"reason\\":\\")(.+?)(?=\\")/

S
Shellr57s, 2022-02-06
@Shellr57s

\breason\b.+\K(?:\bdebt\b|\bnotify\b|\banother\b)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question