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
Post a Comment