Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Following info i want to extract from a file which has different version,release date,CVE number. Can anyone show me how to retrieve that information using regex..? Sorry if this is a terrible question, I can just never grasp RegEx.

    Release date: March 13, 2007
    Vulnerability identifier: APSB07-07
    CVE number: CVE-2007-1278
    Platform: Windows only
share|improve this question

closed as off-topic by dobey, Braiam, Eric Carvalho, guntbert, Radu Rădeanu Oct 1 '13 at 20:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – dobey, Braiam, Radu Rădeanu
If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

2 Answers 2

up vote 4 down vote accepted

If you can't wrap your head around regex, then don't use it. In most cases you can substitute it with regular Python string functions.

Small example for your data:

>>> s = """    Release date: March 13, 2007
...     Vulnerability identifier: APSB07-07
...     CVE number: CVE-2007-1278
...     Platform: Windows only"""
>>> for line in s.split("\n"):
...     if "Release date:" in line:
...         print line.split("Release date: ")[1]
...     if "CVE number:" in line:
...         print line.split("CVE number: ")[1]
... 
March 13, 2007
CVE-2007-1278
>>>

This can be improved ofcourse, but it's just to show you that it's quite easy without regex.

Never forget the famous quote:

Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.

share|improve this answer
    
I have a file which has different platform,release date,CVE number,How can do that....? –  Kummi_10 Sep 30 '13 at 15:08
    
@Kummi_10: just replace the s variable and s.split("\n") in the example with the data read from the file. Probably something like with open("mydata.txt", "r") as infile: infile.read() –  Timo Sep 30 '13 at 16:05
add comment

Depending on what information you want extracted from the above string, you can use something like this regex tester. Any time I write a regex, I use this to make sure it works first.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.