Matching regular expressions with special REGEX symbols and line breaks

0

I need help in a regular expression that matches (% ) in a string whose:

  • beginning is the end of a line with the character }
  • continue marrying everything you find on the next line (including other escaped characters like \ )
  • up to another character } at the end of the back line.

I tried various combinations and I could not.

Thanks for the help, in advance!

    
asked by anonymous 02.06.2017 / 18:47

1 answer

3

I'll assume that regex flavor is similar to php , one of the most common.

I'll also assume that escaped characters are line breaks, something that the " . " operator does not capture, so you can use this regex here:

}(.|\n)*?}

Explanation:

  • } determines that it will only start capturing if a key is closed.
  • ( declares the start of the catch group.
  • .|\n causes it to catch any character that is not a line break, or a line break (in the end, any character).
  • ) declares the end of the capture group.
  • *? quantifying lazy , ensuring that it will stop the catch on the first occurrence of the keys' date, preventing it from capturing unnecessary things if there is more than one occurrence of {} in the code.
  • } sets key closure condition to end capture

You can test it here

    
02.06.2017 / 20:48