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. Windows Forms
  4. RegEx not finding matches ... but it should

RegEx not finding matches ... but it should

Scheduled Pinned Locked Moved Windows Forms
regexhelpcsharpcomsales
4 Posts 2 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.
  • A Offline
    A Offline
    Adam R Harris
    wrote on last edited by
    #1

    *************************** For the record this is a cross-post. I dont want to get anyone mad it's just that i really need help with this Original Post[^] *************************** Hey All, I am experiencing a strange issue, i have built and tested my RegEx in Expresso but when I call it from my code (C#) I am not getting any matches. If i step through and grab the values from the variables and put those in Expresso it works .... RegEx: Lead\sID\sNumber:\s*(?<LeadNumber>[^\r\n]*)(?:\r\n)+ Prospect\sName:.*(?:\r\n)+ Prospect\sContact:.*(?:\r\n)+ Prospect\sPhone:.*(?:\r\n)+ Marketing\sCampaign:.*(?:\r\n)+ Prospect\sInformation:\s*(?:\r\n)+ ===============\s(?:\r\n)+ (?<Company>[^\r\n]*)(?:\r\n)+ (?<Address1>[^,]*),\s(?<Address2>[^\r\n]*)(?:\r\n)+ (?<City>[^,]*),\s(?<State>[^\r\n]*)(?:\r\n)+ (?<Country>[^,]*),\s(?<Zip>[^\r\n]*)(?:\r\n)+ Contact\sName:\s*(?<FirstName>[^\s]*)\s(?<LastName>[^\r\n]*)(?:\r\n)+ Contact\sPhone:\s*(?<Phone>[^\r\n]*)(?:\r\n)+ C#: MatchCollection myMatches = Regex.Matches([Text], [RegEx], RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant); [Text] = the body of an email [RegEx] = the above pattern Any input or ideas would be greatly appreciated.

    L 1 Reply Last reply
    0
    • A Adam R Harris

      *************************** For the record this is a cross-post. I dont want to get anyone mad it's just that i really need help with this Original Post[^] *************************** Hey All, I am experiencing a strange issue, i have built and tested my RegEx in Expresso but when I call it from my code (C#) I am not getting any matches. If i step through and grab the values from the variables and put those in Expresso it works .... RegEx: Lead\sID\sNumber:\s*(?<LeadNumber>[^\r\n]*)(?:\r\n)+ Prospect\sName:.*(?:\r\n)+ Prospect\sContact:.*(?:\r\n)+ Prospect\sPhone:.*(?:\r\n)+ Marketing\sCampaign:.*(?:\r\n)+ Prospect\sInformation:\s*(?:\r\n)+ ===============\s(?:\r\n)+ (?<Company>[^\r\n]*)(?:\r\n)+ (?<Address1>[^,]*),\s(?<Address2>[^\r\n]*)(?:\r\n)+ (?<City>[^,]*),\s(?<State>[^\r\n]*)(?:\r\n)+ (?<Country>[^,]*),\s(?<Zip>[^\r\n]*)(?:\r\n)+ Contact\sName:\s*(?<FirstName>[^\s]*)\s(?<LastName>[^\r\n]*)(?:\r\n)+ Contact\sPhone:\s*(?<Phone>[^\r\n]*)(?:\r\n)+ C#: MatchCollection myMatches = Regex.Matches([Text], [RegEx], RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant); [Text] = the body of an email [RegEx] = the above pattern Any input or ideas would be greatly appreciated.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I would debug such beast using "binary search", i.e. throw away half of the search specification, and keep doing that until something matches. Then you know the problem is in the part you last removed. OTOH I would never come up with such a complex Regex pattern in the first place. It is just unreadable. And what happens if someone somewhere decides to add/delete a space, a new line, whatever to the e-mail format? IMO you need several smaller operations to extract the fields individually, your code looks like a maintenance nightmare to me. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      A 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I would debug such beast using "binary search", i.e. throw away half of the search specification, and keep doing that until something matches. Then you know the problem is in the part you last removed. OTOH I would never come up with such a complex Regex pattern in the first place. It is just unreadable. And what happens if someone somewhere decides to add/delete a space, a new line, whatever to the e-mail format? IMO you need several smaller operations to extract the fields individually, your code looks like a maintenance nightmare to me. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        A Offline
        A Offline
        Adam R Harris
        wrote on last edited by
        #3

        Hello Luc, Normally i would agree with you 200%, however this is a subcontract project which is going to be used by other developers. They wanted me to allow for configuration of the email parsing by having a setting which contains the RegEx to use. You can find the solution to my problem here[^], i didn't want to keep cross posting. Thanks again for your input.

        If at first you don't succeed ... post it on The Code Project and Pray.

        L 1 Reply Last reply
        0
        • A Adam R Harris

          Hello Luc, Normally i would agree with you 200%, however this is a subcontract project which is going to be used by other developers. They wanted me to allow for configuration of the email parsing by having a setting which contains the RegEx to use. You can find the solution to my problem here[^], i didn't want to keep cross posting. Thanks again for your input.

          If at first you don't succeed ... post it on The Code Project and Pray.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          That's interesting. Thanks. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          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