Monday, 8 August 2016

PYTHON MODULE :- REGULAR EXPRESSIONS MODULE

IMPORTING THE MODULE
  import re

ABOUT THE MODULE 
 It provides regular expressions matching that provided in Perl . It is used to perform actions on stings mainly. Certain special characters are offered new meanings in this module

THE split() FUNCTION 
  it is used to split strings with multiple delimiters unlike the usual split function. 
    SYNTAX:-
   result=re.split(<delimiters> ,<>,<>,<buffer>,maxsplit=0,flags=0)
    REPORT:-
  The split() has the ability to split strings at points where it finds patterns (delimiters).It stores the result in form of a list.
for removing all characters other than alphanumeric, the METACHARACTER \w  is used .
>>> re.split(r'[^\w]', 'toto"t"o/t!')
['toto', 't', 'o', 't', '']



SOME EXAMPLES
>>> re.split('\W+', 'Words, words, words.')
['Words', 'words', 'words', '']
>>> re.split('(\W+)', 'Words, words, words.')
['Words', ', ', 'words', ', ', 'words', '.', '']
>>> re.split('\W+', 'Words, words, words.', 1)
['Words', 'words, words.']
>>> re.split('[a-f]+', '0a3B9', flags=re.IGNORECASE)
['0', '3', '9']
 


No comments:

Post a Comment