Skip to main content

Add your description here

Project description

gap-mapper

PyPI version License: MIT

A simple Python utility to find a "gapped" or "sparse" string within a text and return its original offsets.

This is useful when you need to find a string that has had extra, arbitrary spaces inserted into it.

Installation

Install the package from PyPI:

pip install gap-mapper

Usage

The main function is gapmap().

It takes an original_text (the haystack) and a spaced_needle (the gapped string to find). It finds the needle (ignoring its spaces) within the original text (also ignoring its spaces) and returns the correct (start, end) offsets of the match in the original text.

import gap_mapper

# The full text to search within
haystack = "Hello, world! This is the main text."

# The string to find, which has extra, inconsistent spaces
needle = "w   o r l   d"

# Find the offsets
offsets = gap_mapper.gapmap(haystack, needle)

if offsets:
    print(f"Match found at offsets: {offsets}")
    
    start, end = offsets
    print(f"Matched string: '{haystack[start:end]}'")
else:
    print("No match found.")

Match found at offsets: (7, 12) Matched string: 'world'

As you can see, gapmap correctly located "world" in the haystack and returned its true offsets (7, 12), even though the needle was "w o r l d".

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gap_mapper-0.2.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gap_mapper-0.2.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file gap_mapper-0.2.0.tar.gz.

File metadata

  • Download URL: gap_mapper-0.2.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for gap_mapper-0.2.0.tar.gz
Algorithm Hash digest
SHA256 227d84fd6b98a8e44b13d65cb8183a38fbfb6cfe4d012308ef711f580a92efad
MD5 a52c88f08453f1d7c536f3817bcb0716
BLAKE2b-256 fe0f5968ddac1c1b9191503d242bfd780b20556db07a4a7d220d32e19fa7cfc2

See more details on using hashes here.

File details

Details for the file gap_mapper-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gap_mapper-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for gap_mapper-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 545716a04921ffb465cf1b5ceef4282f773bc9b2a21c8c6802ce46d6ae1e44a6
MD5 ede754c8d8404797a122e0331012a8c0
BLAKE2b-256 8b38f34f5e5114382e2a0c308ed2f1ec3439a235d9b958664998de20c3f5e81b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page