Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

javascript - 如何捕捉两个(编号)标记之间的所有内容,包括换行符? [重复](How to catch everything between two (numbered) markers, including line breaks? [duplicate])

I'm trying to capture everything between two markers ( START[number] and END[number] ) where number also needs to be extracted.(我试图捕获两个标记( START[number]END[number] )之间的所有内容,其中数字也需要提取。)

I need to support line breaks.(我需要支持换行符。) For instance the following :(例如以下内容:) START[1] message to capture ...END[1] must return :(必须返回:) group 1 : 1(小组1: 1) group 2 : message to capture ...(第2组: message to capture ...) group 3 : 1(第3组: 1) Here is my attempt ( demo ):(这是我的尝试( 演示 ):) START[(d+)]((.| | )*?)END[(d+)] It doesn't work as I obtain a third group made of the last character of the message to capture and I don't know why.(当我获得由要捕获的消息的最后一个字符组成的第三组时,它不起作用,我也不知道为什么。) Can someone may help me with this ?(有人可以帮我吗?) Thanks.(谢谢。)   ask by Malick translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use [\s\S] instead of (.|\n|\r)(使用[\s\S]代替(.|\n|\r))

START[(d+)]([sS]+?)END[(d+)] Demo(演示版) To be sure to have the same number in START and END, use a backreference to group 1:(为确保在START和END中具有相同的编号,请对组1使用向后引用:) (Credit to Aaron de Windt in comment)((对Aaron de Windt进行评论)) START[(d+)]([sS]+?)END[(1)]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...