case-insensitive

Python Regex to Capture Proceeding Text – mixing cas insensitivity in group

Python Regex to Capture Proceeding Text – mixing cas insensitivity in group Question: Example Link RegEx Group returning issue: (?P<qa_type>(Q|A|Mr[.|:]? [a-z]+|Mrs[.|:]? [a-z]+|Ms[.|:]? [a-z]+|Miss[.|:]? [a-z]+|Dr[.|:]? [a-z]+))?([.|:|s]+)? Objective: To extract text from proceeding transcript pdfs for each question/answer/speaker type. Using Python: interage through pages in PDF extracted text and group Qestion/Answer text. Desired Results = qa_type, page_start, …

Total answers: 1

Case-insensitive comparison of lists

Case-insensitive comparison of lists Question: I want to make a code that to see if each new username has already been used in a website. I have this code: current_users = [‘Rachel’, ‘Ross’, ‘Chandler’, ‘Joey’, ‘Monica’] new_users = [‘Janice’, ‘Ben’, ‘Phoebe’, ‘JOEY’] for new_user in new_users: if new_user in current_users: print (f’The username {new_user} is …

Total answers: 1

A case insensitive string class in python

A case insensitive string class in python Question: I need to perform case insensitive string comparisons in python in sets and dictionary keys. Now, to create sets and dict subclasses that are case insensitive proves surprisingly tricky (see: Case insensitive dictionary for ideas, note they all use lower – hey there’s even a rejected PEP, …

Total answers: 3

Case insensitive argparse choices

Case insensitive argparse choices Question: Is it possible to check argparse choices in case-insensitive manner? import argparse choices = [“win64”, “win32”] parser = argparse.ArgumentParser() parser.add_argument(“-p”, choices=choices) print(parser.parse_args([“-p”, “Win32”])) results in: usage: choices.py [-h] [-p {win64,win32}] choices.py: error: argument -p: invalid choice: ‘Win32’ (choose from ‘win64′,’win32’) Asked By: Peter || Source Answers: Transform the argument into …

Total answers: 4

Case Insensitive Flask-SQLAlchemy Query

Case Insensitive Flask-SQLAlchemy Query Question: I’m using Flask-SQLAlchemy to query from a database of users; however, while user = models.User.query.filter_by(username=”ganye”).first() will return <User u’ganye’> doing user = models.User.query.filter_by(username=”GANYE”).first() returns None I’m wondering if there’s a way to query the database in a case insensitive way, so that the second example will still return <User u’ganye’> …

Total answers: 7

Case-insensitive string startswith in Python

Case-insensitive string startswith in Python Question: Here is how I check whether mystring begins with some string: >>> mystring.lower().startswith(“he”) True The problem is that mystring is very long (thousands of characters), so the lower() operation takes a lot of time. QUESTION: Is there a more efficient way? My unsuccessful attempt: >>> import re; >>> mystring.startswith(“he”, …

Total answers: 7

case-insensitive list sorting, without lowercasing the result?

case-insensitive list sorting, without lowercasing the result? Question: I have a list of strings like this: [‘Aden’, ‘abel’] I want to sort the items, case-insensitive. So I want to get: [‘abel’, ‘Aden’] But I get the opposite with sorted() or list.sort(), because uppercase appears before lowercase. How can I ignore the case? I’ve seen solutions …

Total answers: 9

Querying MongoDB (via pymongo) in case insensitive efficiently

Querying MongoDB (via pymongo) in case insensitive efficiently Question: I’m currently creating a website in python (pyramid) which requires users to sign up and log in. The system allows for users to choose a username which can be a mixture of capital letters, lowercase letters, and numbers. The problem arises when making sure that two …

Total answers: 3

Case insensitive replace

Case insensitive replace Question: What’s the easiest way to do a case-insensitive string replacement in Python? Asked By: Adam Ernst || Source Answers: The string type doesn’t support this. You’re probably best off using the regular expression sub method with the re.IGNORECASE option. >>> import re >>> insensitive_hippo = re.compile(re.escape(‘hippo’), re.IGNORECASE) >>> insensitive_hippo.sub(‘giraffe’, ‘I want …

Total answers: 10

Case insensitive regular expression without re.compile?

Case insensitive regular expression without re.compile? Question: In Python, I can compile a regular expression to be case-insensitive using re.compile: >>> s = ‘TeSt’ >>> casesensitive = re.compile(‘test’) >>> ignorecase = re.compile(‘test’, re.IGNORECASE) >>> >>> print casesensitive.match(s) None >>> print ignorecase.match(s) <_sre.SRE_Match object at 0x02F0B608> Is there a way to do the same, but without …

Total answers: 11