Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Python Regex Help

Posted on 2012-03-26
3
Medium Priority
?
502 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
[X]
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
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
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 …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

618 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