• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(15664)  |  Call(15566)  |  Derive(0)  |  Import(98)
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl.  repl can be either a string or a callable;
if a string, backslash escapes in it are processed.  If it is
a callable, it's passed the match object and must return
a replacement string to be used.

        def sub(pattern, repl, string, count=0, flags=0):
    """Return the string obtained by replacing the leftmost
    non-overlapping occurrences of the pattern in string by the
    replacement repl.  repl can be either a string or a callable;
    if a string, backslash escapes in it are processed.  If it is
    a callable, it's passed the match object and must return
    a replacement string to be used."""
    return _compile(pattern, flags).sub(repl, string, count)
        


src/n/l/nltk-HEAD/nltk/examples/school/categories.py   nltk(Download)
def map1(tag):
    tag = re.sub(r'fw-', '', tag)     # foreign words
    tag = re.sub(r'-[th]l', '', tag)  # headlines, titles
    tag = re.sub(r'-nc', '', tag)     # cited
    tag = re.sub(r'ber?', 'vb', tag)  # verb "to be"
    tag = re.sub(r'hv', 'vb', tag)    # verb "to have"
    tag = re.sub(r'do', 'vb', tag)    # verb "to do"
    tag = re.sub(r'nc', 'nn', tag)    # cited word
    tag = re.sub(r'z', '', tag)       # third-person singular
    return tag
 
def map2(tag):
    tag = re.sub(r'\bj[^-+]*', 'J', tag)  # adjectives
    tag = re.sub(r'\bp[^-+]*', 'P', tag)  # pronouns
def map2(tag):
    tag = re.sub(r'\bj[^-+]*', 'J', tag)  # adjectives
    tag = re.sub(r'\bp[^-+]*', 'P', tag)  # pronouns
    tag = re.sub(r'\bm[^-+]*', 'M', tag)  # modals
    tag = re.sub(r'\bq[^-+]*', 'Q', tag)  # qualifiers
    tag = re.sub(r'\babl',     'Q', tag)  # qualifiers
    tag = re.sub(r'\bab[nx]',  'D', tag)  # determiners
    tag = re.sub(r'\bap',      'D', tag)  # determiners
    tag = re.sub(r'\bd[^-+]*', 'D', tag)  # determiners
    tag = re.sub(r'\bat',      'D', tag)  # determiners
    tag = re.sub(r'\bw[^-+]*', 'W', tag)  # wh words
    tag = re.sub(r'\br[^-+]*', 'R', tag)  # adverbs
    tag = re.sub(r'\bto',      'T', tag)  # "to"
    tag = re.sub(r'\bc[cs]',   'C', tag)  # conjunctions
    tag = re.sub(r'\br[^-+]*', 'R', tag)  # adverbs
    tag = re.sub(r'\bto',      'T', tag)  # "to"
    tag = re.sub(r'\bc[cs]',   'C', tag)  # conjunctions
    tag = re.sub(r's',         '',  tag)  # plurals
    tag = re.sub(r'\bin',      'I', tag)  # prepositions
    tag = re.sub(r'\buh',      'U', tag)  # interjections (uh)
    tag = re.sub(r'\bex',      'E', tag)  # existential "there"
    tag = re.sub(r'\bvbn',     'VN', tag) # past participle
    tag = re.sub(r'\bvbd',     'VD', tag) # past tense
    tag = re.sub(r'\bvbg',     'VG', tag) # gerund
    tag = re.sub(r'\bvb',      'V', tag)  # verb
    tag = re.sub(r'\bnn',      'N', tag)  # noun
    tag = re.sub(r'\bnp',      'NP', tag) # proper noun
    tag = re.sub(r'\bnr',      'NR', tag) # adverbial noun
    tag = re.sub(r'\bnn',      'N', tag)  # noun
    tag = re.sub(r'\bnp',      'NP', tag) # proper noun
    tag = re.sub(r'\bnr',      'NR', tag) # adverbial noun
    tag = re.sub(r'\bex',      'E', tag)  # existential "there"
    tag = re.sub(r'\bod',      'OD', tag) # ordinal
    tag = re.sub(r'\bcd',      'CD', tag) # cardinal
    tag = re.sub(r'-t',        '', tag)   # misc
    tag = re.sub(r'[a-z\*]',   '', tag)   # misc

src/g/o/google-app-engine-HEAD/lib/webob/docs/wiki-example-code/example.py   google-app-engine(Download)
    def title(self):
        if not self.exists:
            # we need to guess the title
            basename = os.path.splitext(os.path.basename(self.filename))[0]
            basename = re.sub(r'[_-]', ' ', basename)
            return basename.capitalize()
        content = self.full_content

src/g/o/google_appengine-HEAD/lib/webob/docs/wiki-example-code/example.py   google_appengine(Download)
    def title(self):
        if not self.exists:
            # we need to guess the title
            basename = os.path.splitext(os.path.basename(self.filename))[0]
            basename = re.sub(r'[_-]', ' ', basename)
            return basename.capitalize()
        content = self.full_content

src/g/a/gaesdk-python-HEAD/lib/webob/docs/wiki-example-code/example.py   gaesdk-python(Download)
    def title(self):
        if not self.exists:
            # we need to guess the title
            basename = os.path.splitext(os.path.basename(self.filename))[0]
            basename = re.sub(r'[_-]', ' ', basename)
            return basename.capitalize()
        content = self.full_content

src/n/l/nltk-HEAD/nltk/examples/school/words.py   nltk(Download)
def read_text(filename):
    "Load the file into a text string, normalising whitespace."
    text = open(filename).read()
    return re.sub('\s+', ' ', text)
 
###############################################################################
### SEARCHING

src/n/o/notmm-0.4.1/examples/lib/satchmo_ext/product_feeds/templatetags/satchmo_feed.py   notmm(Download)
def atom_tag_uri(url, date=None):
    tag = re.sub('^https?://', '', url)
 
    if date:
        tag = re.sub('/', ',%s:/' % date.strftime('%Y-%m-%d'), tag, 1)
 
    tag = re.sub('#', '/', tag)
def stripspaces(s):
    s = re.sub(r'^\s+', '', s)
    s = re.sub(r'\s+$', '', s)
    s = s.replace('\n\n','\n')
    return s
 
register.filter('stripspaces', stripspaces)

src/n/l/nltk-HEAD/trunk/nltk-old/contrib/nltk_contrib/misc/shoebox/bin/bird_example_rev.py   nltk(Download)
def cv(s):
    s = s.lower()
    s = re.sub(r'[^a-z]', r'-', s)
    s = re.sub(r'[aeiou]', r'V', s)
    s = re.sub(r'[^V-]', r'C', s)
    return(s)
 

src/n/l/nltk-HEAD/nltk-old/contrib/nltk_contrib/misc/shoebox/bin/bird_example_rev.py   nltk(Download)
def cv(s):
    s = s.lower()
    s = re.sub(r'[^a-z]', r'-', s)
    s = re.sub(r'[aeiou]', r'V', s)
    s = re.sub(r'[^V-]', r'C', s)
    return(s)
 

src/c/o/Code-HEAD/DiveIntoPython3/examples/plural2.py   Code(Download)
def apply_sxz(noun):
    return re.sub('$', 'es', noun)
 
def match_h(noun):
    return re.search('[^aeioudgkprt]h$', noun)
 
def apply_h(noun):
    return re.sub('$', 'es', noun)
 
def match_y(noun):
    return re.search('[^aeiou]y$', noun)
 
def apply_y(noun):
    return re.sub('y$', 'ies', noun)

src/c/o/Code-HEAD/DiveIntoPython3/examples/plural1.py   Code(Download)
def plural(noun):
    if re.search('[sxz]$', noun):
        return re.sub('$', 'es', noun)
    elif re.search('[^aeioudgkprt]h$', noun):
        return re.sub('$', 'es', noun)
    elif re.search('[^aeiou]y$', noun):
        return re.sub('y$', 'ies', noun)

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next