Giter Club home page Giter Club logo

tssplit's Introduction

Trivial split for strings with multiple character delimiters, quotes and escaped characters

Downloads Buy Me A Coffee

Installation

pip install tssplit

Usage

Syntax

def tssplit(s, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim='', remark='#'):
    """Split a string by delimiters with quotes and escaped characters, optionally trimming results

    :param s: A string to split into chunks
    :param quote: Quote chars to protect a part of s from parsing
    :param quote_keep: Preserve quote characters in the output or not
    :param delimiter: A chunk separator character
    :param escape: An escape character
    :param trim: Trim characters from chunks
    :param remark: Ignore all characters after remark sign
    :return: A list of chunks
    """

Example

from tssplit import tssplit

tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--',
        quote='"\'', delimiter=':;,', escape='/^', trim='')
['--', '--', '--', '----/------:----"----']

tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--',
        quote='"\'', delimiter=':;,', escape='/^', trim='', quote_keep=True)
['--', '--', '--', '--"--/--"--\'--:--\'--"----']

tssplit('--:--;--,--"--/--"--\'--:--\'--# Ignore this',
        quote='"\'', delimiter=':;,', escape='/^', trim='', quote_keep=True, remark='#')
['--', '--', '--', '--"--/--"--\'--:--\'--']

Changelog

  • 2020.03.28 v1.0 Initial release
  • 2020.03.28 v1.0.1 Many quick fixes to make all things work in PyPI
  • 2020.03.29 v1.0.2 Minor fixes, Readme update, Long description provided
  • 2020.03.29 v1.0.3 Trim option to strip() characters from chunks
  • 2020.03.29 v1.0.4 Multiple characters for quotes, delimiters and escapes
  • 2022.02.04 v1.0.5 Added quote_keep option to preserve quote marks in the output or not
  • 2023.01.12 v1.0.6 Remark characters interrupt string parsing
  • 2024.04.03 v1.0.7 Cosmetics to make pylint happy

tssplit's People

Contributors

mezantrop avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

timcera

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.