Ask Your Question
4

Does a Regex function exist that starts at a specified set of characters and stops when it detects a particular character, while also capturing any line breaks in between?

asked 2022-03-27 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-09-16 19:00:00 +0000

djk gravatar image

Yes, such a regex function exists. Here is an example:

/(?<=STARTING_CHARACTERS)[\s\S]*?(?=STOPPING_CHARACTER)/

Replace "STARTINGCHARACTERS" with the set of characters at which you want to start and "STOPPINGCHARACTER" with the character at which you want to stop. This regex function will match any character, including line breaks, between the starting and stopping characters. The "?" after the "*" makes the matching non-greedy, meaning it will stop at the earliest stopping character it finds. The "(?<=...)" and "(?=...)" are positive look-behind and positive look-ahead assertions that ensure the starting and stopping characters are not included in the matched text.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-03-27 11:00:00 +0000

Seen: 12 times

Last updated: Sep 16 '22