You should make the .+
part non-greedy, by using .+?
, as otherwise it will also capture the opening parenthesis you want to see in the look-ahead part.
Also, in the second part, don't make the \(
optional, otherwise you will be OK in having nothing in your look-ahead to match.
Finally, don't match \r\n
, but the end-of-line anchor $
in combination with the m
flag (so that it matches the end of each line instead of the whole input).
So:
\.(.+?)(?=\(|$)
You see the parenthesis in the match as the .
can also match (
.
The pattern will match the rest of the line after the first dot without backtracking to a (
as the parenthesis in the lookahead is optional \(?
and the assertion will be true.
You could make use of a negated character class not crossing parenthesis or a newline when matching.
\.([^()\r\n]+)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.