1

Edit: Clarification, I am using Sublime text. It appears the problem was in fact the multiline issue. Thank you all for your feedback!

Okay so I'm trying to analyze text blocks similar to this:

Private Sub NAV_VE124_Click()
    'Open the picture in its description field
    Call ShowPic(Me.NAV_VE124.Description)
End Sub 

and the regex pattern (?<=Private Sub )((.*?)(?=_Click))

seems to work to locate NAV_VE124

and yet for some reason (?<=\')((.*?)(?=End))

Does not produce any result...

Also, I would like to combine these two searches so that I only grab the stuff after ' if the other condition is allowed, so any thoughts on how to do that would also be phenomenal.

logi-kal
  • 7,107
  • 6
  • 31
  • 43

2 Answers2

1
(?<=\')((.|\s)*(?=End))

the problem is the multiline...not sure what regex tool your using but just do a (.|\s)* to match anything including newline. If \s doesn't work then find out what matches newline for your tool.

ZzCalvinzZ
  • 151
  • 1
  • 7
  • Make the quantifier lazy, otherwise: https://regex101.com/r/bH5qV7/2 – Jan Feb 11 '16 at 19:15
  • This seems to work in regex101.com emulator but not in Sublime. Thanks for the tip though :) – itchyspacesuit Feb 11 '16 at 19:16
  • Don't use `(.|\s)`, it's *extremely* inefficient, as this [demo](https://regex101.com/r/bH5qV7/3) shows. (It should fail, but it times out instead--and switching to a lazy quantifier doesn't help.) Most flavors/tools support a single-line/DOTALL mode that lets the dot match newlines, and Sublime Text is one of them. – Alan Moore Feb 11 '16 at 19:40
0

If your regex engine supports it, you could come up with:

^Private Sub(.+?)(?=_Click).*\R\s+'(?s)(.+?)(?=End)(?s-)

Tested with Sublime as well.

Jan
  • 42,290
  • 8
  • 54
  • 79