Solved

C# and Regular Expressions

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…

856 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