Issue with RegEx Lookaround where new lines are included [duplicate]

大兔子大兔子 提交于 2019-12-13 02:16:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!