简体   繁体   English

Pattern.compile(“\\\\ [+ \\\\?]”);

[英]Pattern.compile(“\\[.+?\\]”);

In this statement, taken from the Pagerank source code: 在本声明中,取自Pagerank源代码:

Pattern.compile("\\[.+?\\]");

What does the pattern mean? 模式是什么意思? I have tried studying it, it says 2 slashes mean a single slash, but what are the .+? 我试过研究它,它说2斜线意味着一个斜线,但是什么是.+? ?

This string literal: 这个字符串文字:

"\\[.+?\\]"

means this string: 表示此字符串:

\[.+?\]

So this expression: 所以这个表达式:

Pattern.compile("\\[.+?\\]");

means this regex: 意味着这个正则表达式:

\[.+?\]

which means "a literal [ , followed by one or more characters — preferably as few as possible — followed by ] ". 这意味着“文字[ ,后跟一个或多个字符 - 最好尽可能少 - 后跟] ”。 ( . means "any character other than newline"; +? means "one or more of what I just said, and preferably as few as possible".) So overall, the regex matches [____] , where ____ can be anything that doesn't contain a newline, as long as it's at least one character long; .表示“除换行之外的任何字符”; +?表示“我刚才说的一个或多个,最好尽可能少”。)总的来说,正则表达式匹配[____] ,其中____可以是任何不包含换行符,只要它至少有一个字符长; and where ____ won't (normally) contain a ] except possibly as the very first character. 并且____ 不会 (通常)包含一个]除非可能是第一个字符。

For more information about Pattern and regexes in Java, see the documentation for the Pattern class . 有关Java中的Pattern和regex的更多信息,请参阅Pattern类的文档

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

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