So I had this code working for a few months already, lets say I have a table called Categories, which has a string column called name, so I receive a string
and I want to know if any category was mentioned (a mention occur when the string contains the substring: @name_of_a_category), the approach I follow for this was something like below:
categories.select { |category_i| content_received.downcase.match(/@#{category_i.downcase}/)}
That worked pretty well until today suddenly started to receive an exception unmatched close parenthesis
, I realized that the categories names can contain special chars so I decided to not consider special chars or spaces anymore (don't want to add restrictions to the user and at the same time don't want to deal with those cases so the policy is just to ignore it).
So the question is there a clean way of removing these special chars (maintaining the @) and matching the string (don't want to modify the data just ignore it while looking for mentions)?
question from:
https://stackoverflow.com/questions/65839892/how-to-remove-replace-specials-characters-from-a-dynamic-regex-string-on-ruby 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…