Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this regular expression match with extra fields?
    primarykey
    data
    text
    <p>First time poster, long time user. I CAN NOT figure out why this data with this regular expression is passing when it should fail. The quick overview is that I have a text file with pipe delimited data in it. I'm reading each line in one at a time and comparing against a regex for pass/fail.</p> <p>Here is the data in question:</p> <pre><code>|A|00032004|00032004|25 S Kings Highway||Cape Giradeau|MO|63701|345800886888|0000254575|091091|RGT Foods, Inc.|1|345800886888|1|345800886888|1|601103061404806|1|003241699917|0|000000000000|0|000000000000|0|000000000000|0|000000000000| |A|00032005|00032005|1009 Kings Hwy||Rolla |MO|65401|345800885880|0000254564||RGT Foods, Inc.|1|345800885880|1|345800885880|1|601103061404798|1|003241699925|0|000000000000|0|000000000000|0|000000000000|0|000000000000| </code></pre> <p>Here's the basic breakdown: |D,U,or A|ID#|ID#|St Add1|St Add2|City|ST|Zip|#|#|Name|bool|#|bool|#|bool|#|bool|#|bool|#|bool|#|bool|#|bool|#|</p> <p>This is my regular expression (warning: it's kinda long):</p> <pre><code>^[\|]{1}[DUA]{1}[\|]{1}[0-9,A-Z]{8}[\|]{1}[0-9,A-Z]{8}[\|]{1}.{0,25}[\|]{1}.{0,25}[\|]{1}.{0,25}[\|]{1}[A-Z,a-z]{2}[\|]{1}[0-9]{5}[\|]{1}[A-Z,a-z,0-9]{12}[\|]{1}[A-Z,a-z,0-9]{10}[\|]{1}.{0,25}[\|]{1}[0,1]{1}[\|]{1}[0-9]{12}[\|]{1}[0,1]{1}[\|]{1}[0-9]{12}[\|]{1}[0,1]{1}[\|]{1}[0-9]{15}[\|]{1}[0,1]{1}[\|]{1}[0-9]{12}[\|]{1}[0,1]{1}[\|]{1}[0-9]{12}[\|]{1}[0,1]{1}[\|]{1}[0-9]{12}[\|]{1}[0,1]{1}[\|]{1}[0-9]{12}[\|]{1}[0,1]{1}[\|]{1}[0-9]{12}[\|]{1} </code></pre> <p>This is my regex function:</p> <pre><code>//Compare the entire line at once public static bool MatchCCRegEx(string spLine) { try { Regex CCLineCheck = new Regex( Properties.Settings.Default.CCRegExValidationString); Match CCLineMatch = CCLineCheck.Match(spLine); if (CCLineMatch.Success) return true; else return false; } catch (Exception RegExCheckExc) { WELogger.LogEvent("3", "Error running RegEx check on this line:\r\n" + spLine + "\r\n" + RegExCheckExc.ToString()); Environment.Exit(9); return false; } } </code></pre> <p>The example data I gave should fail because there is an extra field between # and Name with a value of 091091. The second line should also fail because of the extra field (but it's empty on that one). I've stared at the regex for hours, because it looks like to me at the "#|#|Name|bool", 091091 would've been put in for name and pass, but "RGT Foods, Inc." shouldn't pass as a 0 or 1...but both lines pass regex, what am i doing wrong?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload