Solved

Regular Expressions

Posted on 2013-01-18
2
235 Views
Last Modified: 2013-01-19
Hi All,

I'm trying to test a string to see if it contains another string. I can't use myString.Contains("string") as the string I'm searching for has to be on the LHS of an "=" symbol. For example,

from: "NumberOfGroups = 8"

I want to be able to test if the string contains the text NumberOfGroups and if true retrieve the value 8. I know I can use the split function using "=" as the delimiter. Does anyone know if I can achive this usinging regular expressions? Thank You.
0
Comment
Question by:naelyan
2 Comments
 
LVL 15

Expert Comment

by:navneethegde
ID: 38793489
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38794477
Try:

using System.Text.RegularExpressions;

...

string toFind = "some string";
string toSearchIn = "This is some string that is on the left of an = sign";
string pattern = Regex.Escape(toFind) + "(?=[^=]*=)";

bool contains = Regex.IsMatch(toSearchIn, pattern);

Open in new window

0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Counting connections to SQL Server through C# 3 32
Media.Imaging 1 18
SqlDataBase 7 48
VB.NET 2008 - SQL Timeout 9 24
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question