Solved

C# and Regular Expressions

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

Technology Partners: 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

Suggested Solutions

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…

751 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