Re: java.regex
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Dec 2005 10:53:25 -0800
friend.05 wrote:
I am an XML file in following manner. I want extract some data necessary data from it. So I was using regular expression. ( java.regex)
---------------------------------------------------------------------------------------------------------------------------------------
<entry type="CVE" name="CVE-2005-0001" seq="2005-0001" discovered="2005-01-12" published="2005-05-02" modified="2005-10-20" severity="High"> - <desc> <descript source="cve">Race condition in the page fault handler (fault.c) for Linux kernel 2.2.x to 2.2.7, 2.4 to 2.4.29, and 2.6 to 2.6.10, when running on multiprocessor machines, allows local users to execute arbitrary code via concurrent threads that share the same virtual memory space and simultaneously request stack expansion.</descript> </desc> - <loss_types>
---------------------------------------------------------------------------------------------------------------------------------------
Can any one suggest what pattern should I use if I want CVE name i.e "CVE - 2005-0001"
and published= "2005-05-02"
Assuming your data always matches the CVE-2005-0001:
import java.util.regex.*;
public class test {
public static void main(String[] args) {
String str = "<entry type=\"CVE\" name=\"CVE-2005-0001\" seq=\"2005-0001\"discovered=\"2005-01-12\" published=\"2005-05-02\" modified=\"2005-10-20\"severity=\"High\">- <desc> <descript source=\"cve\">Race condition in the page fault handler (fault.c) for Linux kernel 2.2.x to 2.2.7, 2.4 to 2.4.29, and 2.6 to 2.6.10, when running on multiprocessor machines, allows local users to execute arbitrary code via concurrent threads that share the same virtual memory space and simultaneously request stack expansion.</descript> </desc>- <loss_types>";
Pattern p = Pattern.compile("(CVE-\\d+-\\d+)");
Matcher m = p.matcher(str);
if (m.find())
System.out.println(m.group(1));
}
}--
Knute Johnson email s/nospam/knute/ .
- Follow-Ups:
- Re: java.regex
- From: friend.05
- Re: java.regex
- References:
- java.regex
- From: friend.05
- java.regex
- Prev by Date: Re: PDA the supports either J2ME or J2SE
- Next by Date: iterator.
- Previous by thread: java.regex
- Next by thread: Re: java.regex
- Index(es):