need to find word in a given lines, the word that need to be find can contain letters and numbers. find first instant of this word. punctuations is as shown (random). need to find exactly as in string "word". punctuation is given as string "p" print: if word is founded its start index
using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks;
namespace egz1 { internal class Program { static void Main(string[] args) { string word = "echo"; string a = "Yesterday896, ./..I walked ..//through the old ,./city—slowly, carefully;" + "hinking about time, memory45, and how ,./6echo .,/;'echo echo,./ [p;l;'echo8756 echo appears everywhere:" + " in streets, ,./in voices54, in \nthoughts,/-+ while people pass by, .,/,laugh, stop, and disappear." + "" + ""; string p = " ,./;'/-+\t"; string pattern = $"[{Regex.Escape(p)}]"; string r = pattern+"+"+word+pattern+"+"; //string r = $@"(^|{pattern}+){word}({pattern}+|$)"; //string r = $@"\b{word}\b"+pattern+"+"; Console.WriteLine(Regex.IsMatch(a,r)); Console.WriteLine(Regex.Match(a, r).Index); Console.WriteLine(Regex.Match(a, r).Value); Console.WriteLine(a); } } }