Write code to get First Positive Number using regex
//package com.book2s; import java.util.StringTokenizer; public class Main { public static void main(String[] argv) { String string = "wer 234 book2s.com"; System.out.println(getFirstPositiveNumber(string)); }//from w ww .ja v a 2 s . c om public static String getFirstPositiveNumber(String string) { if (isEmpty(string)) { return ""; } String[] numbers = string.split("([^\\d]+)"); if (numbers.length > 0) { return numbers[0]; } return ""; } public static boolean isEmpty(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(str.charAt(i)) == false) { return false; } } return true; } public static String[] split(String str, String delim) { return split(str, delim, true, false); } public static String[] split(String str, String delim, boolean trim, boolean include) { StringTokenizer tokens = new StringTokenizer(str, delim, include); String[] result = new String[tokens.countTokens()]; int i = 0; while (tokens.hasMoreTokens()) { String token = tokens.nextToken(); if (trim) { token = token.trim(); } result[i++] = token; } return result; } }