Python Forum
Help with re.search()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with re.search()
#1
Hi

I need help writing a re.search() method inside the Book class (see below), that will allow me to search for a string or part of a string, and return whether one of the three books has a title that matches or partly matches the search string. Something like:

    def search_string(what do I enter here?):
        if re.search(what do I enter here?) 
            return print(f"{search_string} has been found in the following book titles: {self.title.title()}")
        else:
            return print(f"Sorry. But no book titles match your search {search_string}")
import re
class Book:
    def __init__(self, title):
        self.title = title
    def __str__(self):
        return self.title.title() + " is a great book!"

dune = Book('dune')
lotr = Book('lord of the rings')
dragonlance = Book('dragonlance')
print(dune)
I hope you can help me out.

In advance, thanks for helping me out.

Best regards Chris
Reply


Messages In This Thread
Help with re.search() - by Sigwulfr - Mar-22-2021, 07:48 PM
RE: Help with re.search() - by BashBedlam - Mar-22-2021, 07:56 PM

Forum Jump:

User Panel Messages

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