Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Python Regex Help

Posted on 2012-03-26
3
485 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 75

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

829 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