Extract Text Between Two Strings
Set a start and an end marker to collect every match in your text, or to delete them.
What to find
Leave empty to start at the beginning of the line.
Leave empty to stop at the end of the line.
For example b, title or h2. Only matches tags without attributes, such as <b> but not <a href="…">.
Markers are plain text, not regular expressions. Type \t for a tab, \n for a line
break and \\ for a backslash. Each start marker pairs with the next end marker after it, and
nesting is not supported: (a (b) c) gives "a (b".
Line by line, a match never crosses a line break. Whole text lets it.
Whole text, extract only. A line break and the spaces around it become one space.
Goes between extracted matches. \n is a new line, \t a tab, or type
, for a comma list.
Result
How to extract text between two strings
Paste your text on the left, or press Load example to try a short application log. Type a start
marker and an end marker, or press a preset such as Double quotes or
Square brackets to fill both. The result lists every match, one per line, and updates as you
type. Copy it or download it as a .txt file. Everything runs in your browser, so nothing you paste
is sent anywhere.
Markers are plain text, not patterns. A marker can be one character, such as (, or a longer string,
such as user=". Leave the start marker empty to match from the beginning of each line, or the end
marker empty to match to the end of the line. Type \t for a tab, \n for a line break
and \\ for a backslash.
What the options do
- Include the markers in the result returns
[auth]instead ofauth. - Ignore case in markers lets
startmatchSTARTorStart, accented and non-Latin letters included. The results keep their original case. - Only the first match per line gives at most one result per line, handy when the first bracket in each log line holds the level or module.
- Trim results, Skip empty results and Remove duplicates tidy the list. A result made only of spaces counts as empty.
- Output separator goes between results: a new line by default,
,for a comma list or\tfor tabs.
Examples
| Text | Start marker | End marker | Result |
|---|---|---|---|
| She said "yes", then "no". | " | " | yes no |
| [INFO] [auth] login ok | [ | ] | INFO auth |
| total(price, tax) + fee(1) | ( | ) | price, tax 1 |
| Hi {name}, your code is {code} | { | } | name code |
| <a href="/pricing">Pricing</a> | href=" | " | /pricing |
| <title>Home page</title> | <title> | </title> | Home page |
| payment failed for order 1042 after 3 retries | order␣ | ␣after | 1042 |
| timeout: 30s | (empty) | : | timeout |
| ERROR disk full on /dev/sda1 | ERROR␣ | (empty) | disk full on /dev/sda1 |
In the table, ␣ stands for a space. Markers made of whole words, like the last three rows, are the quickest way to pull one value out of every line of a log: an order number, a user name or a duration.
Extract or remove
Extract matches returns only the matches. Remove matches returns your text with
every match deleted and everything else left as it was. With Include the markers off, removing keeps the markers,
so call(x) becomes call(). With it on, they go too, so Hello (world)
becomes Hello . When removing, Trim results and Skip empty results only touch the lines you removed
text from, so you can strip notes like [1] or inline comments and tidy the leftovers without
changing the other lines.
Line by line or whole text
Line by line, the default, a match never crosses a line break. A start marker with no end marker after it on the
same line gives no match, and the status below the result says on how many lines that happened. Choose
Whole text when a match can span lines, such as a paragraph split over several lines or a
/* … */ comment. When extracting, set Line breaks inside a match to Replace with a
space to get each of those matches back on a single line.
Why nested brackets are not supported
The tool uses the shortest match: each start marker pairs with the next end marker after it, and the search
carries on from there. For (a (b) c) the first opening bracket pairs with the first closing one, so
the result is a (b. Matching nested pairs means counting brackets as they open and close, which is a
parser's job, and a JavaScript regular expression can't do it either. Instead:
- Use longer markers that the inner pairs can't match, such as
total(and) +. - If the outer pair closes at the end of the line, leave the end marker empty and delete the last character of each result.
- For JSON, source code or HTML with deep nesting, use a parser for that format.
The regular expression equivalent
Line by line, the tool finds the same matches as a non-greedy regular expression such as
"(.*?)", \[(.*?)\] or href="(.*?)" with the g flag. The
? after .* is what makes it stop at the first end marker instead of the last one. Whole
text mode is the same pattern with the s flag, which lets the dot match line breaks, and Ignore case
is the i flag. The difference is that you don't have to escape characters such as [,
( or ., because markers here are always literal.
Markers work well on HTML you control, but a real parser is safer on HTML from the wild. Attributes can use single quotes or none, carry extra spaces around the equals sign, or appear inside comments and scripts. To list the links on a page, paste its HTML into Extract Links from HTML, which parses it with the browser's HTML parser and lists each link with its anchor text and rel values.
Common uses
Developers use it to pull IDs, user names or durations out of logs, collect quoted strings from code, and list the placeholders in a template. SEOs use it to grab titles, hrefs or image paths from a snippet of HTML, or to strip citation markers from copied text. To narrow the input first, keep only the relevant lines with Filter Lines. To break each result into columns afterwards, use Split Text by Delimiter.
Frequently asked questions
How do I extract text between two strings?
Paste your text, then type a start marker and an end marker, or press a preset such as Double quotes or Square brackets. Every piece of text between them is listed, one per line, as you type. Copy the result or download it as a text file.
How do I get the text between two characters, such as brackets or quotes?
Use the same character as both markers for quotes, or the opening and closing character for brackets: ( and ), [ and ], { and }. The presets fill both markers for you. When the markers are the same, each pair of quotes gives one match.
How do I remove the text between two characters?
Choose Remove matches. Your text comes back with every match deleted. Tick Include the markers in the result to delete the brackets or quotes as well, or leave it unticked to keep them.
Does it work with nested brackets?
No. Each start marker pairs with the next end marker after it, so (a (b) c) gives a (b. Use longer markers that the inner pairs can't match, or a parser for the format, such as JSON or HTML.
Can a match span several lines?
Yes, with Whole text. By default the tool works line by line and a match never crosses a line break. In Whole text, you can keep the line breaks inside each match or turn them into spaces.
What if I leave the start or end marker empty?
An empty start marker matches from the beginning of each line, and an empty end marker matches to the end of the line. So an empty start with : as the end marker gives everything before the first colon on each line. At least one marker must be set.