PicoToolkit
Extracted data:
0 characters
0 without spaces
0 words
0 lines
IndexValue
No matching items found
Spotted a bug or have an idea for a new feature? Let us know here »

Extract Text Between Two Strings

Extract text between two strings or simple regex patterns

Quickly pull substrings located between a prefix and a suffix. Enter the text to scan, provide a prefix and a suffix, then run extraction. The tool treats your prefix and suffix as parts of a JavaScript regular expression and searches the whole input case‑insensitively and globally.

Working on: extract-text-between

How to use

  • Paste your source text into the editor.
  • Enter the prefix (the text that appears before the part you want).
  • Enter the suffix (the text that appears after the part you want).
  • Click Extract. The tool returns every matched substring that starts at your prefix and ends at your suffix.

Pattern behavior — what the tool actually does (in plain words)

  • The tool builds a search pattern that looks for your prefix, then one or more characters, then your suffix. It finds all occurrences across the entire input and ignores case.
  • Because your prefix and suffix are placed directly into the search pattern, any regex syntax you type (for example: \d, |, +, character classes, etc.) will be interpreted as regex. If you type only plain text, the engine will still treat that text as part of the pattern (so some characters used by regex may need escaping if you intend them literally).
  • Matches are greedy by default: when multiple matching suffixes exist after a prefix, a single match can span from the first prefix to a later suffix. To avoid overly large spans, make your suffix (or prefix) more specific or use the Pattern Extractor for advanced regex control.
  • The search is global and case‑insensitive by default, so the tool returns all matches regardless of case. Results include the full matched substring (including the prefix and suffix). If you need only the inner content (without delimiters), remove the delimiters afterward or use an advanced extractor that supports capture groups.

Practical tips (no code shown)

  • Want literal matching? Escape regex metacharacters in your prefix/suffix (characters like ., *, +, ?, |, (, ), [, ], {, }, ^, $ and backslash have special meaning). If you do not escape them, the tool will treat them as regex operators.
  • If matches span too far (greedy behavior), narrow your suffix or prefix so the pattern can stop sooner — for example, include surrounding context that is unique to the target occurrence.
  • For complex needs (non‑greedy matching, capture groups, lookarounds or multi‑line flags), use the Pattern Extractor tool — it supports full regex input and returns precise captures for advanced workflows.
  • If you need only the text between delimiters (without the delimiters themselves), either post-process the matched results to strip the prefix/suffix, or use Pattern Extractor and extract capture groups directly.

Examples

  • Extract text inside parentheses (literal case)
    Input:
    Item A (ID: 1234)
    Item B (ID: 5678)
    Item C
    
    Prefix: (
    Suffix: )
    
    Result (matches returned by the tool):
    (ID: 1234)
    (ID: 5678)
    
    Tip: to get only "ID: 1234" and "ID: 5678", remove the surrounding parentheses from the results afterward or use an advanced extractor that supports capture groups.
    
  • Extract product model between words
    Input:
    Mobile phone Samsung Galaxy S20 price $700
    Mobile phone Nokia 3310 price $50
    
    Prefix: Mobile phone 
    Suffix:  price
    
    Result:
    Samsung Galaxy S20
    Nokia 3310
    
  • User-provided regex in prefix/suffix (advanced)
    Input:
    foo12abcbar
    foo3xyzbaz
    foo999zzzbar
    
    Prefix: foo\d+
    Suffix: bar|baz
    
    Result:
    foo12abcbar
    foo3xyzbaz
    foo999zzzbar
    
    Explanation: because the prefix and suffix include regex tokens, the tool treats them as patterns and matches the full substrings that start with foo followed by digits and end with either bar or baz. If you only want the middle parts (e.g., "abc", "xyz", "zzz"), use a dedicated regex tool that returns capture groups.
    
  • Extract text between HTML tags (quick method)
    Input:
    
    Important: read this
    Another note
    Prefix: <div class="note"> Suffix: </div> Result: Important: read this Another note Note: if the HTML is complex or contains nested tags, consider cleaning it first with the HTML Stripper or using the Pattern Extractor for precise regex extraction.
  • Avoiding over‑spanning matches (strategy)
    Problem:
    Start A ... Start B ... End A ... End B
    
    If you use Prefix: Start and Suffix: End, a single match might span from the first Start to the last End.
    
    Workaround:
    Make the suffix more specific (include extra surrounding text unique to each End), or run a pattern extractor that supports non‑greedy or anchored patterns to capture the smaller chunks.
    

Use cases — many practical examples

  • Extract IDs placed in parentheses or brackets (e.g., product SKUs, order numbers).
  • Pull model names or titles from lines that follow a fixed label (e.g., between "Model:" and "Price").
  • Extract text inside specific HTML tags or attributes when you paste page source.
  • Strip out inline notes or markers that are consistently wrapped by delimiters.
  • Harvest fields from exported logs or CSV lines where the desired value sits between two known markers.
  • Quickly inspect multiple matches across a large document without writing a full regex — type readable prefixes/suffixes and scan results.

FAQ

Is my input treated as literal text or regex?

Both. The tool inserts your prefix and suffix directly into the search pattern, so any regex constructs you include will be interpreted as regex. If you enter plain text, it becomes part of the pattern and will match literally unless it contains regex metacharacters (in which case those characters will act as regex operators unless escaped).

Which matching rules and flags are applied?

The search runs globally (finds all matches) and is case‑insensitive by default. This means every matching occurrence in the document is returned regardless of letter case.

What part of the match is returned?

The tool returns the full matched substring — that is, the prefix plus the text in between plus the suffix. If you need only the inner text without delimiters, remove the delimiters from the results afterward or use a tool that supports capture groups.

How do I prevent matches from spanning too far?

Make your prefix and/or suffix more specific so the pattern has a clear boundary. In practice this means including extra context around the ending token or restricting the suffix to text that uniquely identifies the end of the desired segment. For complex non‑greedy behavior, use the Pattern Extractor tool which gives full control over regex quantifiers and captures.

Do I need to escape characters?

Yes — if you want characters that are normally special in regular expressions (for example: ., *, +, ?, |, (, ), [, ], {, }, ^, $ and backslash) to be treated literally, escape them. If you do not escape them, they will behave as regex operators and may change matching results.

Can I use multi-line extraction?

The tool searches across the pasted text and returns matches that include line breaks where they occur. For advanced multi-line regex control or special flags, use the Pattern Extractor which supports more detailed regex options.

What if I need capture groups or exact inner text only?

For capture‑group extraction, non‑greedy quantifiers, lookarounds, or other advanced regex features, use the Pattern Extractor. It supports full regex patterns and returns precise captures for downstream processing.

Related tools

If you want, I can publish this draft and also suggest meta title/description options. Reply PUBLISH to save.

PicoToolkit evolves fast. Stay ahead.

Get early access to new tools, features, and productivity upgrades.

Unsubscribe anytime.
© PicoToolkit 2022-2026 All rights reserved. Before using this website read and accept terms of use and privacy policy. Icons by Icons8