Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snaptext

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snaptext

Tools for manipulating strings while retaining source positions in the resulting object

  • 0.1.1
  • PyPI
  • Socket score

Maintainers
1

Snaptext

Snaptext is a Python package that provides tools for manipulating strings while retaining source positions in the resulting object.

Installation

$ pip install snaptext

Usage

Indexing, concatenation and stripping

from snaptext import Source

source = Source("123 / 456")

source[0:4].area.format()
# =>
# 123 / 456
# ^^^^

source[0:4].strip().area.format()
# =>
# 123 / 456
# ^^^

(source[0:3] + source[-3:]).area.format()
# =>
# 123 / 456
# ^^^   ^^^

Regular expression matching


text = Source("Pi is about 3.1415.")
match = text.transform_match(text.search(r"(\d+)\.(\d+)"))

match.group().area.format()
# =>
# Pi is about 3.1415.
#             ^^^^^^

match.group(2).area.format()
# =>
# Pi is about 3.1415.
#               ^^^^

Regular expression substitution


text = Source("The sum of 3.02 and 12.8 is 15.82")

result = text.sub(r"(\d+)\.(\d+)", r"\1,\2")
# => 'The sum of 3,02 and 12,8 is 15,82'

result.area.format()
# =>
# The sum of 3.02 and 12.8 is 15.82
# ^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^ ^^

Example: JSON parser


from snaptext.json import loads

result = loads("""
{
  "a": "x",
  "b": [13, 14, 15],
  "c": true
}
""")

result.value['b'].value[1].area.format()
# =>
#    "b": [13, 14, 15],
#              ^^

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc