Java-8 regex negative lookbehind with `\R`

前端 未结 2 2075
青春惊慌失措
青春惊慌失措 2020-12-31 23:28

While answering another question, I wrote a regex to match all whitespace up to and including at most one newline. I did this using negative lookbehind for the \\R

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 23:43

    The construct \R is a macro that surrounds the sub expressions into an atomic group (?> parts ).

    That's why it won't break them apart.

    A note: If Java accepts fixed alternations in a lookbehind, using \R is ok, but if the engine doesn't, this would throw an exception.

提交回复
热议问题