DotNET regex



  •  Does anyone have a clue about the exact explanation of this regular expression (used in .NET app) ?

     

     expression = "^(\d+|)$"

     

    thx 

     

     

     

     



  • @bert67 said:

     Does anyone have a clue about the exact explanation of this regular expression (used in .NET app) ?

    expression = "^(\d+|)$"

    Yes thanks. http://www.codeproject.com/KB/dotnet/regextutorial.aspx (first Google match for [.net regex tutorial]) contains everything that will allow you to work it out for yourself.

    You may find http://catb.org/~esr/faqs/smart-questions.html useful as well. 



  • @http://catb.org/~esr/faqs/smart-questions.html said:

    Stupid:

    How do I get the color-picker on the FooDraw program to take a hexadecimal RGB value?

    Smart:

    I'm trying to replace the color table on an image with values of my choosing. Right now the only way I can see to do this is by editing each table slot, but I can't get FooDraw's color picker to take a hexadecimal RGB value.

    Am I the only one seeing this in reverse?


    The first question gets to point directly, but the second is filled with unnecessary babble.



  • Yeah, right 🙂

    at the beginning of ..... any digit or any series of digits.... until exact end of string

    but what i cannot make sense of is the |-character in that exact combination.

     expression = "^(\d+|)$"

    WTF is it doing there ? and how does it alter the exact signification of the regex ?

     

    Thanks for the links anyway.  They're very useful for quick researches.

     



  • @bert67 said:

    but what i cannot make sense of is the |-character in that exact combination.

    That's strange - it's clearly explained in the first URL I gave you. Does your web browser not have any extra functionality if you press Ctrl-F? 



  • @CapitalT said:

    Am I the only one seeing this in reverse?
    The first question gets to point directly, but the second is filled with unnecessary babble.
    No.  You removed the context as well.

     The first is "I can't do my <solution>" with the implication that the solution is the wrong one since <problem> hasn't been stated. The second is "I have <problem>, I think i need <solution> - how do I do <solution>" giving others more of a chance to say <solution> is the wrong way to solve <problem>.

    Can you honestly tell me you've never been on a programming list where a thread goes on for ages trying to explain how to solve something, and at the end of it all, find out that all that effort was wasted because it was an entirely wrong way about solving the unmentioned problem an OP had, and the right solution was completely different (and usually orders of magnitude easier?)

     

    Ususally the answers to first sort of suspect question are phrased on some of the lists I'm on as "What is the problem you think that is the solution for?"



  •  <quote> To select between several alternatives, allowing a match if either one is satisfied, use the pipe "|" symbol to separate the alternatives. </quote>

    Exactly what I mean :  what is the pipe-symbol doing at that exact position ? it does not give any alternatives.

     (\d+|) ??  selection between \d+ and \d+ and \d+ ??????   you'd think (\d+) would do the job, no ?  so why the pipe-symbol ?

     

     



  • @bert67 said:

    (\d+|) ??  selection between \d+ and \d+ and \d+ ??????   you'd think (\d+) would do the job, no ?  so why the pipe-symbol ?
     

    What's after the pipe? 



  •  ^(\d+|)$

     nothing, that's the problem.

    it doesn say (\d{3}|\d{5}|.....) or anything, just \d+|  

     

     

     

     

     



  • @bert67 said:

    ^(\d+|)$

    nothing,

    Right answer.

    It's looking for

    <start of line>(<one or more digits> or <nothing>)<end of line>

    Basically it'll match a line consisting of only digits, or a totally blank line.

    Now - quite how you differentiate between parsing a blank line and a non-blank line not consisting of purely digits I don't know (there was insufficient context .) Both will, IIRC, return 'nothing,' though I'm willing to be corrected on this last point.



  • Thanks for the explication.

    About the context, this regex comes from a piece of code that is highly dependent of it. The code works, so nobody touches it, but at the same time nobody knows what the hell that regex exactly does.

    again, thanks. 



  • @PJH said:

    @CapitalT said:
    Am I the only one seeing this in reverse? The first question gets to point directly, but the second is filled with unnecessary babble.
    No. You removed the context as well.
    The first is "I can't do my <solution>" with the implication that the solution is the wrong one since <problem> hasn't been stated. The second is "I have <problem>, I think i need <solution> - how do I do <solution>" giving others more of a chance to say <solution> is the wrong way to solve <problem>.
    Can you honestly tell me you've never been on a programming list where a thread goes on for ages trying to explain how to solve something, and at the end of it all, find out that all that effort was wasted because it was an entirely wrong way about solving the unmentioned problem an OP had, and the right solution was completely different (and usually orders of magnitude easier?)

    Ususally the answers to first sort of suspect question are phrased on some of the lists I'm on as "What is the problem you think that is the solution for?"


    Oh, I see. My bad.


    PS: I've always heard that ESR's "documents" are rants in disguise, so I have a little prejudice against him.



  • @bert67 said:

    About the context, this regex comes from a piece of code that is highly dependent of it. The code works, so nobody touches it, but at the same time nobody knows what the hell that regex exactly does.
    This is terrifying. You're working in a shop that (presumably) has multiple programmers, none of whom know how to figure out a simple 8-character regular expression? I'd say get out, but then again you're one of the people who doesn't know what the regex did. So the real WTF here is that you all have jobs.



  • @Welbog said:

    This is terrifying. You're working in a shop that (presumably) has multiple programmers, none of whom know how to figure out a simple 8-character regular expression? I'd say get out, but then again you're one of the people who doesn't know what the regex did. So the real WTF here is that you all have jobs.
    At least this way they're all contained in one place, instead of them lurking within our companies.



  • @bstorer said:

    At least this way they're all contained in one place, instead of them lurking within our companies.

    And once we get their coordinates locked into the Navi-puter, we may not have to fear WTFs ever again. 



  • What I do find slightly worrying is that someone wrote (\d+|) instead of (\d*) in the first place. What kind of person knows about regular expressions, knows about its union operation, but not its Kleene closure operation? Do I even want to know?



  • @Welbog said:

    What I do find slightly worrying is that someone wrote (\d+|) instead of (\d*) in the first place. What kind of person knows about regular expressions, knows about its union operation, but not its Kleene closure operation? Do I even want to know?
    It was somebody whose regex-fu is weak. They literally transferred the idea "a string of digits or nothing" to regex, without making the deductive leap to \d*.



  • It's people like the original regex author who give truth to the statement "You have a problem and you want to solve it with a regular expression.  Now you have two problems."  Just surf through regexlib.com and your eyes will bleed...  In the hands of too many people, regexes are just another way to "solve" a problem in the most convoluted way possible.



  • @GalacticCowboy said:

    regexes are just another way to "solve" a problem in the most convoluted way possible.

    I agree that regular expressions can get pretty cryptic, but it does well for pattern matching, captures, and similar tasks. Having to write all this in code might get pretty intensive, so I don't think you can say its the most convoluted way possible.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.