Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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..?

    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.

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

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....? – Naive 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: – Timo Sep 30 '13 at 16:05

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

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