Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PT11H30M
- PT11H
- PT2H
- PT30M
- Pattern.compile("^PT(\d{1,2}H)?(\d{2}M)?$")
- val pattern = Pattern.compile("^PT(\d{1,2}H)?(\d{2}M)?$")
- val matcher1 = pattern.matcher("PT11H32M")
- val matcher2 = pattern.matcher("PT11H")
- val matcher3 = pattern.matcher("PT32M")
- if (matcher1.matches()) {
- val groupsCount = matcher1.groupCount()
- android.util.Log.d("foobar", "M1 count [$groupsCount]")
- (0 until groupsCount).forEach {
- val group = matcher1.group(it)
- android.util.Log.d("foobar", "M1, group [$it], [$group]")
- }
- }
- if (matcher2.matches()) {
- val groupsCount = matcher2.groupCount()
- android.util.Log.d("foobar", "M2 count [$groupsCount]")
- (0 until groupsCount).forEach {
- val group = matcher2.group(it)
- android.util.Log.d("foobar", "M2, group [$it], [$group]")
- }
- }
- if (matcher3.matches()) {
- val groupsCount = matcher3.groupCount()
- android.util.Log.d("foobar", "M3 count [$groupsCount]")
- (0 until groupsCount).forEach {
- val group = matcher3.group(it)
- android.util.Log.d("foobar", "M3, group [$it], [$group]")
- }
- }
- foobar : M1 count [2]
- foobar : M1, group [0], [PT11H32M]
- foobar : M1, group [1], [11H]
- foobar : M2 count [2]
- foobar : M2, group [0], [PT11H]
- foobar : M2, group [1], [11H]
- foobar : M3 count [2]
- foobar : M3, group [0], [PT32M]
- foobar : M3, group [1], [null]
Add Comment
Please, Sign In to add comment