dnup1092 dnup1092 - 6 months ago 12
Java Question

What will be the regex for extracting the data from following string

I have to write an application which has to extract the first 16 digits (

0989563275315984
) ,
crtext
,
tiff
and
1.0_xcvb-uploadtheDoc-hkl56895-20990415-05:11:24,897-2013027676


0989563275315984-1.0_xcvb-uploadtheDoc-hkl56895-20990415-05:11:24,897-2013027676-crtext-tiff.wrk


The regex I've come up with so far is this:

([0-9a-zA-Z]+)-(\\d\\.\\d[_0-9a-zA-Z]*)-([0-9a-zA-Z]+).([a-zA-Z]+).([0-9]?).*


Is there any way to write an regex for this requirement. Thanks in advance.

Answer

Try this

(\d{16})-(.*?)-(\w+)-(\w+)\.

Regex demo

Explanation:
( … ): Capturing group sample
\: Escapes a special character sample
.: Any character except line break sample
*: Zero or more times sample
?: Once or none sample
\w: "word character": ASCII letter, digit or underscore sample
+: One or more sample

Comments