Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex and case insensitive
#3
(Jul-19-2020, 07:57 PM)bowlofred Wrote: I don't see what's actually doing the lookup. But if render_template uses python regex engine, you can probably add a (?i) to the beginning of the regex.

>>> re.search("Hi", "what is this?")
>>> re.search("(?i)Hi", "what is this?")
<_sre.SRE_Match object; span=(9, 11), match='hi'>


I'm using a form to look for an ingredients, the webpage will show me a page with the result of all the recipes with that ingredients.

@app.route('/search', methods=["POST"])
def search():
    if request.method == "POST":
        data = request.form.to_dict()
        keyword = str(data['mysearch'])
        query={"ingredients": { "$regex": keyword }}
    return render_template("search.html", recipes=mongo.db.recipes.find(query))
This code is in main.py, my code works, the only thing is that I would like it looks for case insensitive, for example if I write parmisan, it gives me many results, but if I write ParMiSan none, because it's looking in case sensitive mode. I just would like to know how to add the option to make it case insensitive.
Reply


Messages In This Thread
regex and case insensitive - by Leon79 - Jul-19-2020, 06:44 PM
RE: regex and case insensitive - by bowlofred - Jul-19-2020, 07:57 PM
RE: regex and case insensitive - by Leon79 - Jul-19-2020, 08:13 PM
RE: regex and case insensitive - by bowlofred - Jul-19-2020, 08:26 PM
RE: regex and case insensitive - by Leon79 - Jul-19-2020, 08:28 PM
RE: regex and case insensitive - by bowlofred - Jul-19-2020, 08:31 PM
RE: regex and case insensitive - by Leon79 - Jul-19-2020, 08:37 PM
RE: regex and case insensitive - by bowlofred - Jul-19-2020, 08:53 PM
RE: regex and case insensitive - by Leon79 - Jul-20-2020, 11:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Switch case or match case? Frankduc 9 4,636 Jan-20-2022, 01:56 PM
Last Post: Frankduc
  If this and that "case insensitive" tester_V 5 2,343 Aug-23-2020, 05:37 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020