有人可以帮我解决这两个正则表达式:
First: "^\\s+|\\s+$"
Second: "\\s{2,}"
答案 0 :(得分:1)
看看这个或用谷歌搜索。解释那些正则表达式并不复杂。
http://www.regular-expressions.info/reference.html#
例如:
\ s匹配空格 {2,}表示其中的2个或更多
答案 1 :(得分:0)
为什么不使用工具dat可以“记录”表达式?这可以帮助您理解它们。
使用RegexBuddy(但在我看来是付费的最佳工具),表达式记录如下:
// ^\s+|\s+$
//
// Options: ^ and $ match at line breaks
//
// Match either the regular expression below (attempting the next alternative only if this one fails) «^\s+»
// Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
// Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s+»
// Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
// Or match regular expression number 2 below (the entire match attempt fails if this one fails to match) «\s+$»
// Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s+»
// Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
// Assert position at the end of a line (at the end of the string or before a line break character) «$»