Browse the docs

Find in text

Finds dates, links, emails, phone numbers, addresses, flights, colours, numbers, money, lengths of time, hashtags or mentions in text.

Find kind in text

Details #

Looks through text for one kind of thing and returns everything it finds, in reading order. The result is the step's output and, with into, a variable. Finding nothing is not an error: you get an empty list.

kind is one of:

  • date: a date or time in everyday wording (next Friday at 3pm, Nov 14 at 9:30). value is seconds since 1970; a duration in seconds is added when the text gives one.

  • link: a web address. value is the link.

  • email: an email address. value is the address, without mailto:.

  • phone: a phone number, as written.

  • address: a street address. value is a record with street, city, state, zip and country.

  • flight: a flight such as UA 123. value is a record with airline and flight.

  • color: #rgb, #rrggbb, #rrggbbaa, rgb() or hsl() written in the text. value is the record parseColor returns. Colour names in ordinary prose are not matched.

  • number: a plain number with grouping, decimals, a minus or a percent (1,234.50, -5, 12%). value is the number.

  • money: $12.50, EUR 3, 12 USD, £1,200. value is a record with amount and currency.

  • duration: a length of time with a unit (1h 30m, 90 minutes, 2 days). value is seconds.

  • hashtag: #idea. value is the tag without the #.

  • mention: @kyle. value is the name without the @. An email address is not a mention.

  • all: every kind at once. Where two matches overlap, the more specific one wins (link, email, phone, address, flight, date, money, duration, colour, number, hashtag, mention), so the digits of a phone number are not also a number.

Each item is a record with kind, text (what matched), start and length (counted in UTF-16 units, as macOS counts text) and value.

With first on, the result is only the first item, or nothing when there is none.

Parameters #

ParameterTypeRequiredValuesWhat it does
texttextYesThe text to look through.
firstyes / noReturn only the first item instead of a list. Off by default.
intotextThe variable that receives the result.
kindone ofdate link email phone address flight color number money duration hashtag mention allWhat to find. The default is date.
valuetext

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Find the links in some text
Do
  1. Find link in “Docs at example.com/docs and…”
  2. Show “{{ length(links) }} links” for 2 s
Open in Switchboard to try it

Take the first amount of money:

First price in a message
Do
  1. Find money in “Lunch was $12.50, tip $3”
  2. Show “{{ price.value.amount }} {{ price.value.currenc…” for 2 s
Open in Switchboard to try it

Gotchas #

  • It is safe in a dry run: it only reads the text it is given.

  • Dates are found with the system's own detector, so wording like next Friday is read against the real clock.

  • An unknown kind fails and lists the valid ones.

  • The same search is available in expressions as find and findFirst.

See also #

Transform text, Set variable, Repeat, find, findFirst