JavaScript Search

search() runs a regular expression against the string and returns the index of the first match, or -1 if there is none. Think of it as includes() with regex power and a position instead of a boolean.

Syntax

str.search(regex)

Examples

Input Arguments Output
"a1b2" "[0-9]" 1

Try it live

Type your input and see Search transform it instantly.

Description: Searches for a regular expression in a string and returns the index of the first match.

Example: 'banana bread'.search('bread') => 7

Want to go further? Chain Search with other functions in the visual Playground — pipe one output into the next and watch your data transform.

Related functions

© 2026 Heifara Buval