我在数据库中存储了一些文本,如下所示:
let text = "<p>Some people live so much in the future they they lose touch with reality.</p><p>They don't just <strong>lose touch</strong> with reality, they get obsessed with the future.</p>"
Run Code Online (Sandbox Code Playgroud)
文本可以有许多段落和 HTML 标签。
现在,我还有一句话:
let phrase = 'lose touch'
Run Code Online (Sandbox Code Playgroud)
我想要做的是搜索phrasein text,并返回包含phraseinstrong标签的完整句子。
在上面的例子中,即使第一个段落也包含短语'lose touch',它应该返回第二个句子,因为在第二个句子中,该短语在strong标签内。结果将是:
They don't just <strong>lose touch</strong> with reality, they get obsessed with the future.
Run Code Online (Sandbox Code Playgroud)
在客户端,我可以用这个 HTML 文本创建一个 DOM 树,将它转换成一个数组并搜索数组中的每个项目,但在 NodeJS 中文档不可用,所以这基本上只是带有 HTML 标签的纯文本。我如何在这段文本中找到正确的句子?
我正在尝试将Amazon RDS DB连接到我的nodeJs应用程序,但出现错误和这样的配置
const connection = mysql.createConnection({
host: '***********.*************.************.amazonaws.com',
user: '**********',
password: '************',
database: '************',
port: '3306',
});
connection.connect((err) => {
if (!err) {
start();
}
});
Run Code Online (Sandbox Code Playgroud)