Regex compare two numbers
Is there some way to compare two numbers in a regex? I want a regex that is correct for 10-12, but not correct for 12-10. I mean 10 should be less than 12. I want to do this in Javascript.
If the input is always in XY form, then why not use the split () function with '-' as separator and then compare the two parts s>
You cannot compare numeric values โโusing RegExps.
I would not use regex for this. I would divide the line with the operator, and then compare the two resulting numbers on the basis of a statement I found (I guess 10+12
      
        
        
        
      
    , and 12+10
      
        
        
        
      
    both are legal).
The problem is that you are trying to turn two problems into one.
Regex does a great job of syntax (i.e. recognizes numbers), but garbage in semantics (i.e. recognizes meaning). So a regex will definitely help you recognize x-y
      
        
        
        
      
    , but you are asking too much to get into reasoning about the relationship between x
      
        
        
        
      
    and y
      
        
        
        
      
    .
How often cited;
Some people, when faced with a problem, think, "I know, I will use regular expressions." They now have two problems. ( JWZ )
Or rather, you now have three.