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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building a Product Recommendation Engine With Neo4j — No ML Library Required
  • 6 Techniques To Reduce LLM API Costs With the Python Library
  • 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

Trending

  • Beyond Token Intelligence: Why AI Code Review Needs Cognitive Architectures
  • When Production Stops Moving: Running Claude Code Across a Distributed Enterprise Integration Team
  • Software Quality Habits and AI
  • Using Graph RAG and Specialized Agents to Repair Playwright Tests
  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

  • Building a Product Recommendation Engine With Neo4j — No ML Library Required
  • 6 Techniques To Reduce LLM API Costs With the Python Library
  • 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

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