SheepDev

Text and regular expressions

Split a delimited list without losing empty items

Tools to use

Move alpha,beta,gamma into a line-based input, or combine lines into one setting. Consecutive separators, a trailing separator and surrounding spaces all affect the result. Round-trip a short list in Split and Join before applying the same rules to a long one.

Separate the split delimiter from the joiner

Three-item input
alpha,beta,gamma

Choose split mode, comma as delimiter and newline as joiner. The result has three lines. Change only the joiner to ' | ' to obtain alpha | beta | gamma. The input delimiter identifies boundaries; the output joiner controls their representation.

A literal backslash followed by n differs from a newline. Enable escape interpretation when using the written sequence \n; do not confuse it with an actual newline. If the output visibly contains \n, inspect that setting. The same distinction applies to \t and tabs.

Consecutive delimiters expose empty items

Input containing empty items
alpha,,gamma,

There are four items: alpha, empty, gamma, empty. Make empties visible with prefix [, suffix ] and joiner ' | ': [alpha] | [] | [gamma] | []. An empty display does not imply an unnecessary item. Removing it can shift positional correspondence.

If empty items may be removed, make that a separate cleanup rule and record the count before cleanup. Brackets added for inspection are not original data. Decide whether they belong in the destination format rather than forwarding diagnostic decoration accidentally.

Trimming changes values

Input for observing surrounding spaces
 alpha , beta ,gamma 

Trimming produces alpha, beta and gamma; disabling it retains surrounding spaces. Whether that is desirable depends on the data contract. It may clean human labels but alter fixed-width data or space-sensitive keys. Wrappers such as [ alpha ] help reveal what remains.

Joining cannot restore spaces already removed. Split and join are not a reversible pair after trimming or adding wrappers. For an exact round-trip test, preserve spaces, add nothing and use the original delimiter again.

The delimiter is literal, not a regex or CSV grammar

A comma inside quoted text
alpha,"beta,gamma",delta

Literal comma splitting also splits the comma inside the quotes. Unlike a CSV parser, this tool does not interpret CSV quoting. Use CSV Editor for quoted addresses or notes. A comma-containing list and a CSV document do not necessarily share the same grammar.

Writing \s+ does not mean a regular-expression whitespace pattern. Pattern-based work needs a different workflow, such as checking matches in Regex Tester. If a delimiter can also occur in values, recovering the original items requires an escaping or quoting contract; guessing is not sufficient.

Check the final empty line before joining

Join mode treats input lines as items. Three lines become alpha,beta,gamma, but a trailing newline can create a final empty item and trailing comma. Decide whether it is incidental paste formatting or meaningful data before removing it.

Adding quote prefixes does not safely generate SQL literals containing quotes or NULL; use SQL IN Generator. Likewise, wrappers do not replace JSON string escaping. This tool performs explicit text operations, not destination-format validation. Use format-aware tools when the output has a grammar.

Before processing a long list, test normal items, empties, spaces and a trailing newline. Specify what to retain and remove, then verify readability separately from information preservation. Check the count and first/last items when handing the output onward.

Sources

Tools to use

Guides →