给定下面的文本,我想返回具有以下格式的所有文本行的数组,1.SSRDOCSYYHK1/////25AUG52/M//YOUNG/LANDON/KWAN- 1.1
即使它实际上是跨多行的,这也应该是一行
正则表达式:
str.match(/\d{1,2}.SSRDOCSYYHK1\/\/\/\/\/.+?\d\.\d/g)
全文:
var str= "A-CA25592185
A-ERNONREF/CHGFEEPLUSFAREDIF/CXL BY FLT TIME NOVALUE
TKG FAX-NOT PRICED FARE TYPE EX
FOP- 1.CA
G- 1.SSRDOCSWSHK1/////25MAY55/M//YOUNG/LANDON/KWAN - 1.
1
)>MD
2.SSRPSPTYYHK1///25AUG52/M- 1.1
3.SSRDOCSWSHK1/////25AUG52/F//YOUNG/LILY/LIMKUO - 2.1
4.SSRPSPTYYHK1///25AUG52/F- 2.1
5.SSRDOCSWSHK1/////25AUG52/F//YOUNG/ANDREA/LAUREN - 3.1
6.SSRPSPTYYHK1///25AUG52/F- 3.1
7.SSRDOCSWSHK1/////17MAR93/M//YOUNG/ETHAN/WESLEY - 4.1
8.SSRPSPTYYHK1///25AUG52/M- 4.1
9.SSRDOCSWSHK1/////23NOV96/M//YOUNG/WINSTON/JEREMY - 5.1
10.SSRPSPTYYHK1///25AUG52/M- 5.1
11.SSRDOCSYYHK1/////25MAY55/M//YOUNG/LANDON/KWAN - 1.
1
12.SSRDOCSYYHK1/////04MAR59/F//YOUNG/LILY/LIMKUO - 2.1
13.SSRDOCSYYHK1/////25AUG52/F//YOUNG/ANDREA/LAUREN - 3.1
)>MD
7.SSRDOCSWSHK1/////25AUG52/M//YOUNG/ETHAN/WESLEY - 4.1
8.SSRPSPTYYHK1///25AUG52/M- 4.1
9.SSRDOCSWSHK1/////25AUG52/M//YOUNG/WINSTON/JEREMY - 5.1
10.SSRPSPTYYHK1///25AUG52/M- 5.1
11.SSRDOCSYYHK1/////25MAY55/M//YOUNG/LANDON/KWAN - 1.
1
12.SSRDOCSYYHK1/////25AUG52/F//YOUNG/LILY/LIMKUO - 2.1
13.SSRDOCSYYHK1/////25AUG52/F//YOUNG/ANDREA/LAUREN - 3.1
14.SSRDOCSYYHK1/////25AUG52/M//YOUNG/ETHAN/WESLEY - 4.1
15.SSRDOCSYYHK1/////25AUG52/M//YOUNG/WINSTON/JEREMY - 5.1
**** ITEMS SUPPRESSED ****/DR"
我期望一个包含所有匹配项的数组,但由于换行符可能以以下任何方式发生并且当前不会匹配,因此第 11 行的两个实例不匹配:
var str="1.SSRDOCSYYHK1/////25AUG52/M//
YOUNG/LANDON/KWAN- 1.1"
var str="1.SSRDOCSYYHK1/////25AUG52/M//YOUNG/LANDON/KWAN- 1.
1"
var str="1.SSRDOCSYYHK1/////25AUG52/M//YOUNG/LANDON/KWAN- 1
.1"
var str="1.SSRDOCSYYHK1/////25AUG52/M//YOUNG/LANDON/KWAN-
1.1"
var str="1.SSRDOCSYYHK1/////25AUG52/M//YOUNG/LANDON/KWAN
- 1.1"
在上述所有情况下,我如何告诉这个 RegExp 仍然匹配?
我确实尝试str.match(/\d{1,2}.SSRDOCSYYHK1\/\/\/\/\/.+?\d\.\d/m)
过但没有运气
这是我得到的数组:
anubhava 下面的答案返回以下数组,请注意,插槽 0 和 2 实际上包含作为单个实例捕获的两行。如果我使用他的示例,当像这样换行并且后面跟着另一个匹配的行时,总是会发生这种情况。