DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Design a Multi-Agent AI Framework in Python for Enterprise LLM Workflows
  • Building a Python API Client That Doesn’t Fall Apart When the API Misbehaves
  • 3D Air Quality Maps With Neo4j, Python, and R
  • Building an Identity-Aware MCP Server in Python

Trending

  • Why Your Terraform Drift Alerts Are Useless (And How to Fix Them)
  • Running Sentiment Analysis Inside Neo4j With a Java Plugin
  • Building Realistic Test Data in Java: A Hands-On Guide for Developers
  • Native SQL in Java Without JDBC Boilerplate — Meet Ujorm3
  1. DZone
  2. Coding
  3. Languages
  4. Handling Accented Characters With Python Regular Expressions

Handling Accented Characters With Python Regular Expressions

By 
Richard Barrett-small user avatar
Richard Barrett-small
·
Feb. 27, 06 · Code Snippet
Likes (0)
Comment
Save
Tweet
Share
7.6K Views

Join the DZone community and get the full member experience.

Join For Free
[A-z] just isn't good enough!


import re
string = 'riché'
print string
riché

richre = re.compile('([A-z]+)')
match = richre.match(string)
print match.groups()
('rich',)

richre = re.compile('(\w+)',re.LOCALE)
match = richre.match(string)
print match.groups()
('rich',)

richre = re.compile('([é\w]+)')
match = richre.match(string)
print match.groups()
('rich\xe9',)

richre = re.compile('([\xe9\w]+)')
match = richre.match(string)
print match.groups()
('rich\xe9',)

richre = re.compile('([\xe9-\xf8\w]+)')
match = richre.match(string)
print match.groups()
('rich\xe9',)

string = 'richéñ'
match = richre.match(string)
print match.groups()
('rich\xe9\xf1',)

richre = re.compile('([\u00E9-\u00F8\w]+)')
print match.groups()
('rich\xe9\xf1',)

matched = match.group(1)
print matched
richéñ


Python (language)

Opinions expressed by DZone contributors are their own.

Related

  • How to Design a Multi-Agent AI Framework in Python for Enterprise LLM Workflows
  • Building a Python API Client That Doesn’t Fall Apart When the API Misbehaves
  • 3D Air Quality Maps With Neo4j, Python, and R
  • Building an Identity-Aware MCP Server in Python

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook