7.4. ReSearch (re)

class easydata.queries.re.ReSearch(query: str, dotall: bool = True, ignore_case: bool = False, bytes_to_string_decode: str = 'utf-8')[source]

Bases: easydata.queries.base.QuerySearch

ReQuery (shortcut: re) allows you to select a value from a text by a regex pattern.

Through this tutorial we will use following text which contains some javascript code in it.

js_text = """
    let spConfig = {
        basePrice: "149.95€",
        prices: {
            basePrice: "0€"
        }
    };
"""

Lets import our easydata module first.

>>> import easydata as ed

Now lets extract basePrice value from our text and pass js_text to our re instance.

>>> ed.re('basePrice: "(.*?)"').get(js_text)
'149.95€'

7.4.1. Pseudo keys

::all

By default out regex pattern will always return fist match. If we want to get list of all matches, then we need to add ::all pseudo key to our regex pattern.

>>> ed.re('basePrice: "(.*?)"::all').get(js_text)
['149.95€', '0€']

7.4.2. Parameters

dotall

By default is set to True.

ignore_case

By default is set to False.

bytes_to_string_decode

By default is set to 'utf-8'.