我正在try 解析一个与下面的字符串类似的字符串.这表示对一本书的查询.有多个选项可用于查找特定字段,因此intitle:专门在书名中查找内容.我有两个问题.
- 它没有解析出第三个返回元素中的一些术语,如inAuthor和inPublisher-‘Champ inAuthor:"John Smith"inPublisher:"the book Place"’-这可能与字符串中的双引号有关?
- 我如何使用双引号使其成为单任期?
字符串:
basketball intitle:champ inauthor:"john smith" inpublisher:"the book place" subject: fiba isbn: 12345 lccn: 689778 oclc: 1234156
我的try
let q: string = `basketball intitle:champ inauthor:"john smith" inpublisher:"the book place" subject: fiba isbn: 12345 lccn: 689778 oclc: 1234156`;
console.log(q);
q = q.replaceAll(`: `, `:`);
console.log(q);
let all = q.split(
/(\bintitle:\b|\binauthor:\b|\binpublisher:\b|\bsubject:\b|\bisbn:\b|\blccn:\b|\boclc:\b)/,
);
console.log(all);
[
'basketball ',
'intitle:',
'champ inauthor:"john smith" inpublisher:"the book place" ',
'subject:',
'fiba ',
'isbn:',
'12345 ',
'lccn:',
'689778 ',
'oclc:',
'1234156'
]