File: automaton_match.rst

package info (click to toggle)
python-pyahocorasick 1.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 748 kB
  • sloc: ansic: 4,554; python: 2,823; sh: 312; makefile: 242
file content (36 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
match(key) -> bool
----------------------------------------------------------------------

Return True if there is a prefix (or key) equal to key present in the trie.

For example if the key 'example' has been added to the trie, then calls to
match('e'), match('ex'), ..., match('exampl') or match('example') all return
True. But exists() is True only when calling exists('example').

Examples
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    >>> import ahocorasick
    >>> A = ahocorasick.Automaton()
    >>> A.add_word("example", True)
    True
    >>> A.match("e")
    True
    >>> A.match("ex")
    True
    >>> A.match("exa")
    True
    >>> A.match("exam")
    True
    >>> A.match("examp")
    True
    >>> A.match("exampl")
    True
    >>> A.match("example")
    True
    >>> A.match("examples")
    False
    >>> A.match("python")
    False