简体   繁体   English

Java正则表达式问题

[英]java regex problem

Suppose I have a string "July is busy". 假设我有一个字符串“ July is busy”。 And I need the string without "July". 而且我需要不带“ July”的字符串。 How can I do it with using regex ? 我如何使用正则表达式来做到这一点?

Thanks. 谢谢。

So you want to remove the first word from a string? 因此,您要从字符串中删除第一个单词吗?

Try 尝试

String resultString = subjectString.replaceAll("^\\s*\\w+\\s*", "");

You can do something like this: 您可以执行以下操作:

import java.util.regex.*;
Matcher m = Pattern.compile("^July(.*)\$").matcher("July is busy");

// if you had a match, the extra would be here:
if (m.matches()) {

    // match count:
    m.groupCount();

    // ' is busy'
    String rightOfJuly = m.group(1);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM