Solved

Python Regex Help

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Basic Regex for use in webservice 1 64
parse convert xml feed to text (python) 2 83
Regular expressions Exclude patter 3 37
regex expression 9 61
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,…
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
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 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…

777 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