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
  1. Home
  2. General Programming
  3. C#
  4. Regular Expression problem

Regular Expression problem

Scheduled Pinned Locked Moved C#
regexhelpcomjsonquestion
3 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.
  • T Offline
    T Offline
    t4ure4n
    wrote on last edited by
    #1

    I have a following regex in my program 01 private void myMethod 02 { 03 string strInput = "http://www.yahoo.com/"; 04 string p = strInput; 05 Regex myRegex = new Regex(@"http://(www\.)(?[^\.]+)\.com", RegexOptions.IgnoreCase); 06 07 MatchCollection MatchList = myRegex.Matches(strInput); 08 09 StringBuilder sb = new StringBuilder(); 10 sb.Append(MatchList.Count + " Matches found\n"); 11 sb.Append("==========================================\n"); 12 rtbOutput.Text = sb.ToString(); 13 } But when i run the program i receie the following error An unhandled exception of type 'System.ArgumentException' occurred in System.dll Additional information: parsing "http://(www\.)(?[^\.]+)\.com" - Unrecognized grouping construct. What am I doing Wrong?

    o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°

    U Mircea PuiuM 2 Replies Last reply
    0
    • T t4ure4n

      I have a following regex in my program 01 private void myMethod 02 { 03 string strInput = "http://www.yahoo.com/"; 04 string p = strInput; 05 Regex myRegex = new Regex(@"http://(www\.)(?[^\.]+)\.com", RegexOptions.IgnoreCase); 06 07 MatchCollection MatchList = myRegex.Matches(strInput); 08 09 StringBuilder sb = new StringBuilder(); 10 sb.Append(MatchList.Count + " Matches found\n"); 11 sb.Append("==========================================\n"); 12 rtbOutput.Text = sb.ToString(); 13 } But when i run the program i receie the following error An unhandled exception of type 'System.ArgumentException' occurred in System.dll Additional information: parsing "http://(www\.)(?[^\.]+)\.com" - Unrecognized grouping construct. What am I doing Wrong?

      o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°

      U Offline
      U Offline
      Urs Enzler
      wrote on last edited by
      #2

      If I'm not mistaken then (? marks the start of a named group (see named group in MSDN). Why do you have the ( and ) anyway?

      -^-^-^-^-^- no risk no funk

      1 Reply Last reply
      0
      • T t4ure4n

        I have a following regex in my program 01 private void myMethod 02 { 03 string strInput = "http://www.yahoo.com/"; 04 string p = strInput; 05 Regex myRegex = new Regex(@"http://(www\.)(?[^\.]+)\.com", RegexOptions.IgnoreCase); 06 07 MatchCollection MatchList = myRegex.Matches(strInput); 08 09 StringBuilder sb = new StringBuilder(); 10 sb.Append(MatchList.Count + " Matches found\n"); 11 sb.Append("==========================================\n"); 12 rtbOutput.Text = sb.ToString(); 13 } But when i run the program i receie the following error An unhandled exception of type 'System.ArgumentException' occurred in System.dll Additional information: parsing "http://(www\.)(?[^\.]+)\.com" - Unrecognized grouping construct. What am I doing Wrong?

        o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°

        Mircea PuiuM Offline
        Mircea PuiuM Offline
        Mircea Puiu
        wrote on last edited by
        #3

        Take the '?' question mark out of the group and put it in front of it, actually marking the fact that (www\.) is optional.

        SkyWalker

        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