Answer the question
In order to leave comments, you need to log in
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:
Here is what I was able to come up with:
word = 'RESPONSIBILITY'
/([A-Z].)*(?=#{word})\s*([A-Z].+:)/
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question