我正在尝试使用正则表达式从字符串末尾删除字符串et al
。可选的是,末尾可以有一个点,并且在此子字符串前面可以有一个逗号和/或多个空格:
https://regex101.com/r/aBw7xy/1
string.replace(/.*(,\s?\s*et\s+al.*)$/g, '')
但这对于这些输入示例的第一行不起作用:
name firstname secondname et al
name firstname secondname, et al
name firstname secondname,et al
name firstname secondname, et al.
name firstname secondname, et al.
name firstn. sec., et al.
name f s, et al.
我想去掉这个子字符串前面的每个et al
和空格/逗号。
结果应该是:
name firstname secondname
name firstname secondname
name firstname secondname
name firstname secondname
name firstname secondname
name firstn. sec.
name f s
如果该组完全匹配,我该如何首先测试?
最佳答案
试试这个:
(,?\s*et\s+al.*)$
你的:.(,\s?\set\s+al.)$ . 将匹配您希望保留的所有内容, \s?不再需要了,因为你有一个\s*
关于javascript - JS/正则表达式 : Remove a substring from end of string with optional comma and spaces in front and dot behind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48106984/