java 方法返回值 和调用方法的对象

agbbbb 2017-10-29 08:06:31
新人正在学正则表达式,看的马士兵老师的视频,学习过程中看到这么一串代码:
Pattern p = Pattern.compile("\\d{3,5}");
String s = "123-34345-234-00";
Matcher m = p.matcher(s);
print(m.find());

上面调用的print()方法:
public static void print(Object o ){
System.out.println(o);
}

上面那段代码里:
第一句,生成一个正则表达式模板,是不是这句执行完了以后,变量p = "\\d{3,5}?
如果是的话,那Pattern型变量也是正则表达式(字符串)?
第三句,p.matcher(s); 这句是把p变成m,还是把穿进去的参数s变成m?
第四句,m.find();找匹配,找m与谁匹配的啊,还是上面这几个语句用的时候是放在一起用的?那才能看出是跟谁匹配?
求高手有时间帮忙回复下,谢谢
...全文
506 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
自由自在_Yu 2017-10-30
  • 打赏
  • 举报
回复
你把每一个都打印出来就知道啦,,,,,,
maradona1984 2017-10-30
  • 打赏
  • 举报
回复
问号太多,你到底想知道什么?
markfengfeng 2017-10-29
  • 打赏
  • 举报
回复
或许Pattern类的注释可以解答: /** * A compiled representation of a regular expression. * * <p> A regular expression, specified as a string, must first be compiled into * an instance of this class. The resulting pattern can then be used to create * a {@link Matcher} object that can match arbitrary {@linkplain * java.lang.CharSequence character sequences} against the regular * expression. All of the state involved in performing a match resides in the * matcher, so many matchers can share the same pattern. * * <p> A typical invocation sequence is thus * * <blockquote><pre> * Pattern p = Pattern.{@link #compile compile}("a*b"); * Matcher m = p.{@link #matcher matcher}("aaaaab"); * boolean b = m.{@link Matcher#matches matches}();</pre></blockquote> * * <p> A {@link #matches matches} method is defined by this class as a * convenience for when a regular expression is used just once. This method * compiles an expression and matches an input sequence against it in a single * invocation. The statement * * <blockquote><pre> * boolean b = Pattern.matches("a*b", "aaaaab");</pre></blockquote> * * is equivalent to the three statements above, though for repeated matches it * is less efficient since it does not allow the compiled pattern to be reused. * * <p> Instances of this class are immutable and are safe for use by multiple * concurrent threads. Instances of the {@link Matcher} class are not safe for * such use. 我英语也二把刀,但是借助翻译软件还是能看懂的。你自己琢磨琢磨。
李德胜1995 2017-10-29
  • 打赏
  • 举报
回复
自己看jdk文档。。。。

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧