[英]How to remove newLines at the beginning and at the end of a Ruby string
[英]How to check for [ ] at beginning and end of string
如何使用正則表達式檢查字符串的[
開頭和]
末尾?
我試圖檢查JSON.parse
是否可以使用該字符串。
/\\A[\\w\\z]/
是我想出來的,但似乎並沒有起作用。
如果你只想在開始和結束時檢查,為什么不
string = "[foo..bar]"
str = string.strip
str[0] == "[" && str[-1] == "]"
由於方括號[]
用於創建正則表達式列表,因此必須將它們轉義:
/\A\[.*\]\z/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.