How to parse this string in Java?

前端 未结 10 1400
感情败类
感情败类 2020-11-29 05:19

prefix/dir1/dir2/dir3/dir4/..

How to parse the dir1, dir2 values out of the above string in Java?

The prefix here c

10条回答
  •  佛祖请我去吃肉
    2020-11-29 05:45

     String result;
     String str = "/usr/local/apache2/resumes/dir1/dir2/dir3/dir4";
     String regex ="(dir)+[\\d]";
     Matcher matcher = Pattern.compile( regex ).matcher( str);
      while (matcher.find( ))
      {
      result = matcher.group();     
      System.out.println(result);                 
    }
    

    output-- dir1 dir2 dir3 dir4

提交回复
热议问题