Python:
# -*- coding: utf-8 -*- import re lib_num_pattern = re.compile(r‘(\d+)\.(\d+)‘) chars = ‘入库179.00件‘ result = lib_num_pattern.search(chars) print(‘re_search:‘, result.group(), result.groups()) print(‘type: ‘, type(result.groups())) print(‘lib_num: ‘, result.groups()[0])
java:
import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexMatches { public static void main( String[] args ){ String line = "入库179.00件"; String pattern = "(\\d+)\\.(\\d+)"; Pattern r = Pattern.compile(pattern); Matcher m = r.matcher(line); if (m.find( )) { System.out.println("Found value: " + m.group() ); System.out.println("Found value: " + m.group(1) ); } else { System.out.println("NO MATCH"); } } }
原文:https://www.cnblogs.com/luckyls/p/14714229.html