[英]Using Regex, how can I get the words "músicas" or "áudio" in a sentence?
I'd like to check a sentence in JavaScript.我想在 JavaScript 中检查一个句子。 I'm using Web Speech API in Portuguese (PT-BR) by Google.
我正在使用 Google 提供的葡萄牙语网络语音 API (PT-BR)。 So code follows:
所以代码如下:
[...]
// Writes the spoken sentence on a field
document.getElementById('text').innerHTML = result;
// Should check whether "músicas" is in sentence or not
if (/músicas/g.test(result) == true)
{
document.getElementById("output").innerHTML = "Inside sentence";
}
else
{
document.getElementById("output").innerHTML = "Not inside sentence";
}
[...]
The variable result stores the spoken sentence in Portuguese, for example, Eu gosto de músicas (Which means I like musics ).变量result存储葡萄牙语的口语句子,例如, Eu gosto de músicas (这意味着我喜欢音乐)。 Then, the conditions should check, but it's not working with accentuations.
然后,应该检查条件,但它不适用于重音。
By the way, if I check something without accentuation, such as /fotos/g , it works perfectly!顺便说一句,如果我检查一些没有重音的东西,例如/fotos/g ,它完美地工作!
Can anybody help me with this probably simple Regex issue?有人可以帮我解决这个可能很简单的正则表达式问题吗?
Thank you.谢谢你。
To match accented vowels in a JavaScript regex, we can use the unicode character class:要匹配 JavaScript 正则表达式中的重音元音,我们可以使用 unicode 字符类:
if (/m[\u00FA]sicas/g.test(result) == true) {
document.getElementById("output").innerHTML = "Inside sentence";
}
You can refer here for a table of accented characters and their Unicode equivalents.您可以在此处参考重音字符表及其 Unicode 等效项。
Note that as others have mentioned, in pure JavaScript you do not need Unicode classes for this, but apparently you have an application which requires this.请注意,正如其他人所提到的,在纯 JavaScript 中,您不需要为此使用 Unicode 类,但显然您有一个需要此功能的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.