使用正则表达式在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
}