Solved

C# and Regular Expressions

Posted on 2013-01-18
2
375 Views
Last Modified: 2013-01-18
Hi,

I'm using a this pattern "\\\\[.*\\\\]" to detect a line in a file which is enclosed by sqaure brackets, for example [Group_1] when I have a match I want to stop reading the file so I use

while (!System.Text.RegularExpressions.Regex.IsMatch(line, pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                        {
                                                //Do Stuff
                        }

Unfortunatley is doesn't work
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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38792250
how are you reading the file?
when you say "doesn't work" => what errors?
0
 
LVL 9

Accepted Solution

by:
sognoct earned 500 total points
ID: 38792375
try to change regular exp in

"\\[[^\\]\\[]+\\]"

Open in new window


my testing sample code
 string pattern = "\\[[^\\]\\[]+\\]";
      string line = "rr[rrrrr]rr";
      if (!System.Text.RegularExpressions.Regex.IsMatch(line, pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) {
        MessageBox.Show("ok"); 
      }

Open in new window

0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

623 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