Solved

Python Regex Help

Posted on 2012-03-26
3
477 Views
Last Modified: 2012-03-27
Hello,

I need some help. Id like to know how to get keywords from output like this:
<meta name="keywords" content="kony2012, psychicpebbles, oneyng, egoraptor, tomamoto, ricepirate, video, cartoon, parody, shove, rocks, down, my, dirty">

Open in new window


So the output would be:
kony2012, psychicpebbles, oneyng, egoraptor, tomamoto, ricepirate, video, cartoon, parody, shove, rocks, down, my, dirty

Id like to use Pythons re.search but in 4 years I still don't know how to use regex. I hate it.
0
Comment
Question by:GVNPublic123
3 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37768176
Is this what you are after (tested in 3.2)?

import re

source = r'<meta name="keywords" content="kony2012, psychicpebbles, oneyng, egoraptor, tomamoto, ricepirate, video, cartoon, parody, shove, rocks, down, my, dirty">'

match = re.search('<meta (?=[^>]*?name="keywords")[^>]*?content="([^"]+)', source)

print(match.group(1))

Open in new window

0
 

Author Closing Comment

by:GVNPublic123
ID: 37768244
perfect thanks
0
 
LVL 10

Expert Comment

by:pfrancois
ID: 37770136
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
looping 11 27
Powershell regex followup 13 69
BASH script to modify crontab? 3 22
Reading text file in Python gives strange results 7 27
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now