04pallav
9/11/2017 - 10:27 PM

regular expressions regex

regular expressions regex

import re
re.search("^new",word) #every word which starts with new
re.search("ful$",word) #every word which ends with ful
re.search("^..nn..$",word) #every word which has nn in between & six characters long
re.search("^[chr]at$",word)] #with "c" or "h" or "t", and end in "at".
re.search("^.*nn.*$",word) #words of any length that have two n's.

Starting with something and ending with something

^library(*)$  ### will not work

keep a part of matched string?

^library\((\w+)\)$   or     this  ::::::   ^library\((.*)\)$ 
suppressMessages(library(\1))



http://ryanstutorials.net/regular-expressions-tutorial/regular-expressions-basics.php

dot (.)
Match any character.
[ ]
Match a range of characters contained within the square brackets.
[^ ]
Match a character which is not one of those contained within the square brackets.
*
Match zero or more of the preceeding item.
+
Match one or more of the preceeding item.
?
Match zero or one of the preceeding item.
{n}
Match exactly n of the preceeding item.
{n,m}
Match between n and m of the preceeding item.
{n,}
Match n or more of the preceeding item.
\
Escape, or remove the special meaning of the next character.