Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

C# and Regular Expressions

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
naelyan
Asked:
naelyan
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
how are you reading the file?
when you say "doesn't work" => what errors?
0
 
sognoctCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now