我正在嘗試編寫能讓我搜索通過表單提交的內容並查找內容中的電子郵件地址的代碼。下面是代碼和我收到的錯誤消息。搜索字符串以查找ruby中的電子郵件地址
Error: undefined method `match' for {"content"=>"this is a test [email protected]"}:ActionController::Parameters
代碼:
class ChallengesController < ApplicationController
def create
@challenge = current_user.challenges.build(challenge_params)
challenge_params.match(/\b[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}\b/i)
# ...
end
private
def challenge_params
params.require(:challenge).permit(:content)
end
end
什麼是你的問題? – sawa
使用正則表達式來查找有效的電子郵件字符串是非常困難的,因爲[有效地址上有大量的變體](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate -an的電子郵件地址)。 –