© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4w ago•
4 replies
Piranija

regex don't work

beginnervisual studio
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);
}
}
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Why my SRP don't work?
C#CC# / help
16mo ago
✅ I don't know why this doesn't work.
C#CC# / help
4y ago
❔ I don't know why this wont work
C#CC# / help
3y ago
Regex help.
C#CC# / help
11mo ago