源代码:

package xyz.jangle.util.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author jangle
 * @email 274676957@qq.com
 * 2025年10月12日 上午9:44:39
 */
public class PatternAndMatch {

	/**
	 * 2025年10月12日 上午9:44:39 @author jangle
	 * @param args
	 */
	public static void main(String[] args) {
		
		Pattern p;
		Matcher m;
		String regex = "[1-9][0-9]*[.]?[0-9]*";
		p = Pattern.compile(regex);
		String s = "Price:123456$,weight:234.78,height:83";
		m = p.matcher(s);
		while(m.find()) {	//寻找s与regex匹配的下一子序列
			String group = m.group();
			System.out.println(group);	//返回该子序列,并打印
		}

	}

}

输出结果:

123456
234.78
83

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐