पढ़ना लाइनों के बीच का उपयोग कर सकते हैं, मैं स्वीकार्य इनपुट की परिभाषा का विस्तार किया और नहीं और: यहाँ एक असफल-सुरक्षित POSIX regex है माना जाता है कि आप केवल वर्णित प्रारूप में संख्या को कैप्चर करना चाहते थे।
उदाहरण के लिए, इन नंबरों सही करने के लिए संख्या के रूप में पकड़ने और सभी स्वीकार्य इनपुट हैं जाएगा:
"0.952321 " 0.952321 (trailing spaces stripped)
" 1.20394 " 1.20394 (leading and trailing spaces stripped)
"12.12" 12.12 (no leading or trailing spaces)
"12.123 " 12.123
" .1234 " .1234 (no leading digit -- start with decimal)
"25" 25 (no decimal)
" " " " ? (space. space captured or not)
"12." 12. (1 or 2 digits, decimal, no numbers after decimal)
ठीक नहीं इनपुट:
"." just a decimal
"123456789" more than 2 digits lefthand
123 "" ""
123.45678
1.1234567 more than 6 digits right hand
[a-zA_Z] not a digit...
तो, कि यह देखते हुए, इस regex करना होगा यह:
/^\s*( # beginning of string and strip leading space
| \d{1,2}\.? # 1 or 2 digits with optional decimal
| \d{0,2}\.\d{1,6} # 0,1, 2 digits with a decimal with digits
| \s+ # remove if you do not want to capture space
)\s*$ # trailing blanks to the end
/x
आप किस भाषा का उपयोग कर रहे हैं? – miorel
खाली से आपका क्या मतलब है? – PierrOz