Get first word from text
From "Hello, world — this is a preview." you get Hello, 5 characters long, and the rest of the line separately. A quoted "Autumn notes" gives Autumn, and ...first-word! gives first-word. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- Hello, world — this is a preview.
- First word
- Hello
- Length
- 5
- Original
- Hello, world — this is a preview.
- Start index
- 0
Getting the first word out of a messy string is a small job that shows up everywhere: title slugs, notification previews, log parsers, and the first token of a command line. This capability reads your text, ignores the whitespace and punctuation that so often wrap a heading or a quoted phrase, and returns the first real word together with its length and the leftover remainder. Leading spaces, tabs, ellipses, quotes, and trailing commas do not become part of the answer, so Hello, world yields Hello rather than a padded or punctuated token.
How first-word extraction works and what counts as a word
Search intent for get first word from text is narrower than a full tokenizer or a unique-word list: people want the opening token of a title, a notification, a log line, or a command, cleaned of the decoration that usually sits around it. This capability defines a word as a maximal run of Unicode letters, combining marks, and digits, optionally joined by an internal apostrophe or hyphen so contractions such as don't and compounds such as well-known stay one token.
Spaces, tabs, line breaks, quotes, commas, ellipses, brackets, and other punctuation are never part of that token. They may appear before the word, after it, or both; they are trimmed rather than returned. The phrase Hello, world therefore yields Hello, a quoted title such as "Autumn notes" yields Autumn, and a line that begins with an ellipsis such as ...first-word!
more text yields first-word. Length is the character length of the surface form that was found, so café counts four characters whether the acute is precomposed or not as a separate search problem—the engine returns the slice that actually sat in the input. After the first match the rest of the string is exposed as remainder, whitespace-trimmed, so a second parse or a preview of the leftover clause is one field away.
What you can do with it
Notification and card previews
Product UIs paste a title or message and show the cleaned first word as a compact badge instead of a padded or punctuated token.
Slug and filename seeds
Editors take the opening word of a headline as a slug seed or a file stem, then apply their own lowercase or hyphen rules.
Command and log parsers
Scripts read the first token of a command line or log message after wrapping quotes, then route on that verb or level name.
FAQ
Does surrounding punctuation stay on the first word?
No. Leading and trailing punctuation and whitespace are trimmed. Hello, becomes Hello, and a quoted Autumn becomes Autumn. Internal hyphens and apostrophes stay.
What counts as a word?
A run of Unicode letters, combining marks, or digits, optionally joined by an internal apostrophe or hyphen. That keeps don't and well-known as one token.
What does the result show besides the word?
Its length in characters and the remainder, which is the text that follows the word with outer spaces removed. For Hello, world it is ", world — this is a preview.", ready for a second pass or a preview.
What happens if the text has no words at all?
It is rejected with a clear message. Empty text, spaces only or punctuation only cannot produce a word, because a word needs at least one letter or digit.
How is it used with log lines or commands?
Scripts read the first token of a command or log message, even when it is wrapped in quotes, and then route on that verb or level name. The quotes and spaces around it are never part of the answer.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/str/first-word \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"Hello, world — this is a preview."}'const res = await fetch("https://api.kit.forhosting.com/str/first-word", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "Hello, world — this is a preview."
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/str/first-word",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "Hello, world — this is a preview."
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/str/first-word", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"Hello, world — this is a preview."}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"Hello, world — this is a preview."}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/str/first-word", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"text": "Hello, world — this is a preview."
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "str.first_word",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_chars | 100000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Wordless strings—empty, spaces only, or punctuation only—fail with invalid_input and are not billed. Successful API calls cost $0.002 per item.
Input contract, response fields, and empty or wordless text
An empty string, a string of only spaces, or a string of only punctuation also fails, because no letter-bearing or digit-bearing word was found—the error message states that text must contain at least one word and that whitespace and punctuation alone are not enough. Remainder is omitted when the input is a single word, never sent as null. POST a JSON body with the required string field text set to the passage you want scanned. Aliases input, value, s, content, and body are accepted so form generators and older clients can post under familiar names. The value must be a string; objects, arrays, booleans, and numbers fail with invalid_input naming the problem. Payloads longer than the documented character cap fail the same way so a single request cannot monopolize Worker memory. Those validation failures are not billed on the prepaid API. On success the response reports first_word as the cleaned opening token, length as its character count, original as an echo of the input for UI tables, start_index and end_index as the offsets of that token inside original, remainder as the leftover string after the word with outer whitespace removed, and method always set to first_word so clients can branch without sniffing shapes. Example: Hello, world — this is a preview. yields first_word Hello, length five, start_index zero, and a remainder that begins with a comma and the rest of the sentence. A padded line such as two spaces, three dots, well-known, and a phrase yields first_word well-known because the hyphen is internal and the leading punctuation is not.
Previews, slugs, parsing pipelines, pricing, and practical limits
Call the free in-browser get first word tool when you need a clean opening token for a card preview, a filename stem, a chat badge, or a command parser that should ignore wrapping quotes. Editorial pipelines use the same call to turn a headline into a short label without dragging the comma or the em dash into the badge. Do not expect stemming, stopword removal, or language detection—those are different searches and different contracts. Developers wire the prepaid KIT API when a CMS, a mobile client, or a batch job needs the same contract under balance at $0.002 per successful item; validation failures never consume balance after the engine rejects the request. A typical workflow pastes a title, reads first_word, and lowercases it locally if a slug helper needs a seed. Pair this endpoint with a slugify or longest-word tool when the next step is a URL or a typography check, but keep get-first-word as its own landing so the opening-token intent is not mixed with full-string slug conversion, word counts, or keyword extraction.
Technical questions
How do I get the first word from a text string?
Send JSON with text set to your passage. The response includes first_word, its length, the start and end offsets, and remainder with whatever follows that word.
What happens if the text has no words?
The request fails with invalid_input. Empty strings and punctuation-only input are rejected and are not billed on the prepaid API.
What does the first-word extractor cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.