how can i extract the content of an ISO-8601 with regex and convert the time into numeric in this case using java -
this text :
<meta itemprop="duration" content="pt4m32.80000000000001s">
i want extract pt4m32.80000000000001s , convert numeric. had tried integer.parseint() gives me numberformatexception. please.
it depends on number want extract, , if context fixed. say, have pt4m
before double
value of 32.80000000000001
want extract.
here sample program:
import java.util.regex.*; public class helloworld{ public static void main(string []args){ string str = "pt4m32.80000000000001s"; pattern ptrn = pattern.compile("(?<=pt4m)[\\d.]+"); matcher matcher = ptrn.matcher(str); if (matcher.find()) { system.out.println(matcher.group(0)); double fl = double.parsedouble(matcher.group(0)); system.out.println(fl); } } }
output:
32.80000000000001 32.80000000000001
Comments
Post a Comment