Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Problems with regular expressions

Problems with regular expressions

Scheduled Pinned Locked Moved C#
regexhelpcom
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pcaeiro
    wrote on last edited by
    #1

    Hello to all, First, sorry for my english. :) I have an aplication where the user should write in a textbox a regular expression, then all the words that matches in an listBox should be selected, and it works fine, but if the user intruduces a bad regular expression (like *a instead of a*) it blows the all thing. How could i fix it. here is part of the code: //////////////////////////////////////////////////////////////////// string exp = textBox1_Tab3_Create6.Text; Regex rexp = new Regex(exp); //compara a substring de cada item com a introduzida e //selecciona se for igual for (int i = 0; i < listBox1_Tab3_Create6.Items.Count; i++) { string word = listBox1_Tab3_Create6.Items[i].ToString(); if (rexp.IsMatch(word)) listBox1_Tab3_Create6.SetSelected(i, true); } /////////////////////////////////////////////////////////////////// Thanks for any help

    L R 2 Replies Last reply
    0
    • P pcaeiro

      Hello to all, First, sorry for my english. :) I have an aplication where the user should write in a textbox a regular expression, then all the words that matches in an listBox should be selected, and it works fine, but if the user intruduces a bad regular expression (like *a instead of a*) it blows the all thing. How could i fix it. here is part of the code: //////////////////////////////////////////////////////////////////// string exp = textBox1_Tab3_Create6.Text; Regex rexp = new Regex(exp); //compara a substring de cada item com a introduzida e //selecciona se for igual for (int i = 0; i < listBox1_Tab3_Create6.Items.Count; i++) { string word = listBox1_Tab3_Create6.Items[i].ToString(); if (rexp.IsMatch(word)) listBox1_Tab3_Create6.SetSelected(i, true); } /////////////////////////////////////////////////////////////////// Thanks for any help

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I guess by "it blows the all thing" you mean you get an exception because the regex is wrong? Nothing easier to fix:

      string exp = textBox1_Tab3_Create6.Text;
      try {
      Regex rexp = new Regex(exp);
      }
      catch(ArgumentException e)
      {
      // something went wrong while parsing the regex, display a message box or something like that
      }

      regards

      P 1 Reply Last reply
      0
      • P pcaeiro

        Hello to all, First, sorry for my english. :) I have an aplication where the user should write in a textbox a regular expression, then all the words that matches in an listBox should be selected, and it works fine, but if the user intruduces a bad regular expression (like *a instead of a*) it blows the all thing. How could i fix it. here is part of the code: //////////////////////////////////////////////////////////////////// string exp = textBox1_Tab3_Create6.Text; Regex rexp = new Regex(exp); //compara a substring de cada item com a introduzida e //selecciona se for igual for (int i = 0; i < listBox1_Tab3_Create6.Items.Count; i++) { string word = listBox1_Tab3_Create6.Items[i].ToString(); if (rexp.IsMatch(word)) listBox1_Tab3_Create6.SetSelected(i, true); } /////////////////////////////////////////////////////////////////// Thanks for any help

        R Offline
        R Offline
        Ravenet
        wrote on last edited by
        #3

        Hi pcaeiro You means when u type "*a" it's show will give error? If it will give error please post that error here because of "it blows the all thing" thanks

        Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com

        P 1 Reply Last reply
        0
        • L Lost User

          I guess by "it blows the all thing" you mean you get an exception because the regex is wrong? Nothing easier to fix:

          string exp = textBox1_Tab3_Create6.Text;
          try {
          Regex rexp = new Regex(exp);
          }
          catch(ArgumentException e)
          {
          // something went wrong while parsing the regex, display a message box or something like that
          }

          regards

          P Offline
          P Offline
          pcaeiro
          wrote on last edited by
          #4

          tanks for the help. The exception works just fine. I think i must work harder... :-O

          1 Reply Last reply
          0
          • R Ravenet

            Hi pcaeiro You means when u type "*a" it's show will give error? If it will give error please post that error here because of "it blows the all thing" thanks

            Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com

            P Offline
            P Offline
            pcaeiro
            wrote on last edited by
            #5

            tanks for the help but i have already solve my problem. :-D

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups