regex - Regular expression help in Python. Looking for an expression for RGB values -


It seems that I need some help with a regular expression to match RGB values ​​I created the following expression But he has not got the match. It is also insufficient because I need to expand it to check for three digits and only a 0-255 value should be present.

For example. The following are all valid values ​​against which I need a match:

  0,0,0 0 0, 0, 0 255,255,255 255, 255, 255   

Here's what I've done so far:

  expression = re.compile (r '(\\ d +), (,), (\\ d +), (,) , (\\ d +) ') expression. Match (text)    

You can insurance number There are between 0 and 255 with a regex, but I highly recommend it against it. Here is an easy way to capture the numbers with the regesx and check that they were in the middle of 0 to 255 just by casting a single int and costing:

  & gt; & Gt; & Gt; Import re & gt; & Gt; & Gt; R = r "(\ d +), \ s * (\ d +), \ s * (\ d +)" & gt; & Gt; & Gt; Rematch (R, "0, 254,10") Group () ('0', '254', '10') >> & Gt; & Gt; All (0 and lt; = int (group) & lt; = 255 again. Group in the match (R, "0, 254,10"). Group ()) True & gt; & Gt; & Gt; Group (R, "0, 256, 190"). Group ()) Incorrect     

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -