Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert letters to lower case

Tags:

python

regex

I use the following with respect to letters from any language:

text = regex.sub("[^\p{alpha}\d]+"," ",text

Can I use p{alpha} to convert letters to their lower case equivalent if such an equivalency exists? How would this regex look?

like image 911
Baz Avatar asked Sep 28 '11 19:09

Baz


People also ask

How do you convert letters to lowercase?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

What converts all letters in a text string to lowercase?

The toLowerCase() method converts a string to lower case letters.

How do you convert a character from uppercase to lowercase?

Program to convert the uppercase string into lowercase using the strlwr() function. Strlwr() function: The strlwr() function is a predefined function of the string library used to convert the uppercase string into the lowercase by passing the given string as an argument to return the lowercase string.


2 Answers

>>> re.sub('[AEIOU]+', lambda m: m.group(0).lower(), 'SOME TEXT HERE')
'SoMe TeXT HeRe'
like image 190
Steven Rumbalski Avatar answered Oct 11 '22 21:10

Steven Rumbalski


As oxtopus suggested, you can simply convert letters to their lowercase version with text.lower() (no need for a regular expression). This works with Unicode strings too (À -> à, etc.)

like image 25
Eric O Lebigot Avatar answered Oct 11 '22 20:10

Eric O Lebigot