regex - python regular expression to validate types of strings -


I want to do the following with a dragon:

  1. If there is a UTF 8 string then Valid integer
  2. Validate if a UTF 8 string is a float.
  3. If a UTF is 8 string length (1-255) then validate.
  4. Validate whether the UTF 8 string is a valid date.

I am totally new to the dragon and I believe that it should be done with regular expression, except that your help for the last one is appreciated!

Reggae is not a good solution here.

  1. If a UTF8 string is an integer then validate:

      Try: int (val) is_in = True Value except error: is_int = False  
  2. Validate if a UTF 8 string is a float: like the above, but float () . Validate

  3. with UTF8 string length (1-255):

      is_of_appropriate_length = 1 & lt; = Len (val) & lt; = 255  
  4. Validate that if a UTF 8 string is a valid date: it is not trivial. If you know the correct form, you can use time.strptime () in this way:

      # Assume that the date is YYYY-MM-DD Try the import time in the format: time.strptime (val, '% y-% m-% d') is_in_valid_format = except for trueError = is: is_in_valid_format = False  
  5. < Edit: Another thing to note is that since you specifically mention the UTF-8 string, they should decode for the first time in Unicode. It will be done by:

      my_unicode_string = my_utf8_string.decode ('utf8')  

    It is interesting to note that when using a Unicode string instance For, you are not limited to "Western Arabic" numbers, which are limited to the digits used in most of the world. Must be interpreted as int (u'17 ') and int (u'17') as 17, although they are Hindu-Arabic and Devangari numbers respectively.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -