* fix: replace sh with shell fix replace terminal with shell fix replace node with js fix replace output with shell fix replace cs with csharp fix replace c++ with cpp fix replace c# with csharp fix replace javasctipt with js fix replace syntax with js fix replace unix with shell fix replace linux with shell fix replace java 8 with java fix replace swift4 with swift fix replace react.js with jsx fix replace javascriot with js fix replace javacsript with js fix replace c++ - with cpp fix: corrected various typos fix: replace Algorithm with nothing fix: replace xaml with xml fix: replace solidity with nothing fix: replace c++ with cpp fix: replace txt with shell fix: replace code with json and css fix: replace console with shell
645 B
645 B
title, localeTitle
title | localeTitle |
---|---|
Match a Literal String with Different Possibilities | 匹配具有不同可能性的文字字符串 |
匹配具有不同可能性的文字字符串
假设您想要将许多不同的单词与正则表达式匹配;使用|
符号,这成为可能。在这个挑战中,您使用该符号来识别隐藏在字符串中的四种不同的宠物!
提示1:
在字符串文字内,放置宠物名称,每个名称由|
分隔符号。
剧透警报 - 提前解决!
解:
let petString = "James has a pet cat.";
let petRegex = /dog|cat|bird|fish/;
let result = petRegex.test(petString);