C
C
caution2015-06-23 18:41:21
ruby
caution, 2015-06-23 18:41:21

How to write such a regex?

Hello. I'm trying to write a regular expression to highlight text to the right and left of a given word, resting on the end of the previous sentence on the left, or on a colon or the end of repetitions on the right. The results that I am trying to achieve on the screen:
12c417205f674040b09777c5f429cbe2.png
Here is what I was able to come up with:

word = 'RESPONSIBILITY'
/([A-Z].)*(?=#{word})\s*([A-Z].+:)/

But it works, to put it mildly, not quite as it should:
834a4fe2238043c5a650d9569459760d.pngc2337f2c99e14796b3043b3ecee309f7.png
Perhaps someone can help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karabanov, 2015-06-23
@caution

Maybe so https://regex101.com/r/kE7wH3/5
In the subpattern with a word, you can leave any one word or add more words through "|"... In general, the searched word should be inserted into this subpattern.

R
Ruslan Saiko, 2015-06-23
@RuslanSaiko

Like so
https://regex101.com/r/kE7wH3/4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question