_?
在以下rails正則表達式中的含義是什麼?_是什麼?在以下正則表達式中意味着什麼?
/\A_?[a-z]_?(?:[a-z0-9.-]_?)*\z/i
我試圖破譯正則表達式如下
# regex explained
# \A : matches the beginning of the string
# _? :
# [ : beginning of character group
# a-z : any lowercase letter
# ] : end of character group
# _? :
# ( : is a capture group, anything matched within the parens is saved for later use
# ?: : non-capturing group: matches below, but doesn't store a back-ref
# [ : beginning of character group
# a-z : any lowercase letter
# A-Z : any uppercase letter
# 0-9 : any digit
# . : a fullstop or "any character" ??????
# _ : an underscore
# ] : end of character group
# _? :
#) : See above
# * : zero or more times of the given characters
# \z : is the end of the string
'_'沒有特別的意義,它只是一個下劃線。 '_?'是一個可選的下劃線。 – Blender 2014-10-09 04:22:12