Solved

Python Regex Help

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with REGEX with 2 different strings 14 56
Python - ImportError: No module named 'urllib2' 2 153
Replace a tag with sed 2 47
Need Regex Money No $ 5 69
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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 strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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 …

911 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

19 Experts available now in Live!

Get 1:1 Help Now