Solved

Regular Expressions

Posted on 2013-01-18
2
232 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 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now