使用正则表达式在java中提取子字符串 [英] extract substring in java using regex

查看:1383
本文介绍了使用正则表达式在java中提取子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从字符串中提取URPlus1_S2_3

I need to extract "URPlus1_S2_3" from the string:

"Last one: http://abc.imp/Basic2#URPlus1_S2_3," 

使用正则表达式用Java语言

using regular expression in Java language.

有人可以帮帮我吗?我是第一次使用正则表达式。

Can someone please help me? I am using regex for the first time.

推荐答案

尝试

Pattern p = Pattern.compile("#([^,]*)");
Matcher m = p.matcher(myString);
if (m.find()) {
  doSomethingWith(m.group(1));  // The matched substring
}

这篇关于使用正则表达式在java中提取子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆