java - Regex to extract lines after the last occurence -
hi have paragraph :
output 123 deepak everywhere deepak output 123 ankur everywhere deepak last deepak everywhere deepak
i want extract after last occurrence of "output 123" "last" . expect :
ankur everywhere deepak last
i use regex pattern - (?<=(output))([^\\n]*)last
. using this, :
output 123 deepak everywhere deepak output 123 ankur everywhere deepak last
can ? use tool - http://regexr.com?360ek
you can use pattern , extract first capturing group:
output\\b[^\\n]*\\s*((?>[^o\\s]++|\\s++(?!last\\b)|o(?!utput\\b))++)(?=\\s+last\b)
details:
output\\b[^\\n]*\\s* # begining (exclude final result # used anchor) ( # open capturing group (?> # open atomic group (all possible content) [^o\\s]++ # not "o" or white character | # or \\s++(?!last\\b) # white characters not followed "last" # (here possessive quantifier needed forbid # backtracks) | # or o(?!utput\\b) # "o" not followed "utput\b" )++ # repeat atomic group 1 or more times ) # close capturing group (?=\\s+last\b) # followed white characters , "last"
you can find content of capturing group with: m.group(1)