w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Using Perl regex to find and extract matches over multiple lines

Try this regex :

/(?s)[Term].*?xref: type1.*?(?=[Term])/g

This regex has the following notable changes:

  • (?s) turns on "dot matches newline"
  • .*? is a non greedy expression. Using .* will consume everything to the last [Term] in the file
  • removed unnecessary grouping around .*?
  • Added slight refinement to match xref, not just type1 anywhere
  • removed incorrect syntax for following Term marker
  • Added a look -ahead to match up to, but not including, the next [Term] marker

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.