LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2012, 08:03 AM   #1
Birdman48
Member
 
Registered: Aug 2008
Location: Southern Maryland
Distribution: ubuntu 14.04 LTS
Posts: 113

Rep: Reputation: 1
Python -simple re question


Hi. I'm messing with regular expressions in python and am trying to match five-letter words in a file. Here's my code:
Code:
wordlist = re.findall(r'\s\w{5}\s', text)
Trouble is it also matches the newline characters. I want a list of five letter words - no newlines. I will look around the docs some more but I would appreciate a quick answer if you have the time. Thanks.
 
Old 10-25-2012, 08:18 AM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
this is better:
Code:
re.findall(r'\b\w{5}\b', text)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Python simple question gary_in_springhill Programming 4 02-19-2010 03:52 AM
very simple python script question slideh Linux - Newbie 6 02-02-2009 11:00 AM
Extremely simple Python question Travis86 Programming 3 01-02-2007 12:50 PM
Simple Python Question peter_89 Programming 3 05-10-2006 11:13 AM
simple python function question Tyir Programming 2 03-28-2004 10:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration