检测消息";嗨";而没有发现他或dfahi
本文关键字:quot 发现 dfahi 消息 检测 | 更新日期: 2023-09-27 18:01:04
我用Discord.net制作了一个机器人。我有http://www.hastebin.com/uyeveqoxur.avrasm它通过"hi containing"检测所有内容我试过了http://pastebin.com/4wVajZ8u
var msg = e.Message.Text.ToLower().Replace("!", " ").Replace("?", " ").Replace(".", " ").Replace(",", "");
您可以将Regex类与此模式一起使用'bhi'b
('b
表示单词边界(
示例:
// need this somewhere at top of file/namespace (or to qualify fully members)
using System.Text.RegularExpressions;
var rgx = new Regex(@"'bhi'b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
var samples = new [] { "Hi someone !", "HI!", "him", "dfahi" };
foreach (var sample in samples)
Console.WriteLine ($"{sample}, Matched : {rgx.IsMatch(sample)}");
输出
嗨,有人!,匹配:true
嗨!,匹配:true
他,匹配:false
dfahi,匹配:错误