问题
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...
Any thoughts would be greatly appreciated.
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 :)
回答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.
回答2:
If your regex engine supports it, you could come up with:
^Private Sub(.+?)(?=_Click).*\R\s+'(?s)(.+?)(?=End)(?s-)
Tested with Sublime as well.
来源:https://stackoverflow.com/questions/35347226/issue-with-regex-lookaround-where-new-lines-are-included