Solved

C# and Regular Expressions

Posted on 2013-01-18
2
368 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
2 Comments
 
LVL 142

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now