Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

regex - MongoDB Regular Expression: Contains an e-mail inside a string

Given that I have a string such as

"Donald Trump <[email protected]>" 
"Art Job <[email protected]>"

How can I find every row that contains "[email protected]" using MongoDB in Rails?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From the documentation:

search_string = params['search']

# Constructor syntax coll.find({"name" => Regexp.new(search_string)})

# Literal syntax coll.find({"name" => /#{search_string}/})

Beware though... You can't use an index with this query since your regex isn't anchored to the front of the string.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...