Solved

Regular Expressions

Posted on 2013-01-18
2
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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