它们只能在行尾不同:"\n" 是 Linux 风格,"\r\n" 是 Windows 风格。
使用
const regex = new RegExp(/([\wà-ú'" ]+)R\$ ([\d+,\.]+)[\n\r]+([ \wà-ú'"\.,\+\*\(\)]+)/)
解释
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[\wà-ú'" ]+ any character of: word characters (a-z,
A-Z, 0-9, _), 'à' to 'ú', ''', '"', ' '
(1 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
R 'R'
--------------------------------------------------------------------------------
\$ '$'
--------------------------------------------------------------------------------
' '
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
[\d+,\.]+ any character of: digits (0-9), '+',
',', '\.' (1 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
) end of \2
--------------------------------------------------------------------------------
[\n\r]+ any character of: '\n' (newline), '\r'
(carriage return) (1 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
( group and capture to \3:
--------------------------------------------------------------------------------
[ \wà- any character of: ' ', word characters
ú'"\.,\+\*\(\)]+ (a-z, A-Z, 0-9, _), 'à' to 'ú', ''',
'"', '\.', ',', '\+', '\*', '\(', '\)'
(1 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
) end of \3