What is REGEX? Technical topics explained simply (2024)

abstract

API Catalog

APIs TO LOOK UP

IP GeolocationPopularGeolocate any IP worldwideCompany EnrichmentPopularGet data on any domain or company
Time, Date, and TimezonesGet any date and timezone globallyPublic HolidaysGet holidays for any countryWeatherGet live and historical global weather data

APIs TO CREATE

Website ScreenshotGet a screeshot of any URLImage ProcessingCompress and optimize an image
Link ShortenerShorten and manage URL’sWeb ScrapingExtract data from any websiteUser AvatarsCreate flexible user avatars

APIs TO VALIDATE

Email ValidationPopularValidate email addressesPhone ValidationPopularValidate phone numbers
IBAN ValidationValidate IBAN codes

Get your free API key now

What is REGEX? Technical topics explained simply (2)

4.8 from 1,863 votes

See why the best developers

build on Abstract

No credit card required

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form.

Resources

API GuidesHTTP Status GuideAPI Glossary
Integrations
LOG INSTART FOR FREE

This website uses cookies to enhance user experience and to analyze performance on our website. Learn more

rejectAccept all cookies
GO BACK

Glossary

Last Updated Jul 09, 2021

Emma Jagger

Table of Contents:

Heading

Get your free

API key now

What is REGEX? Technical topics explained simply (5)

4.8 from 1,863 votes

See why the best developers build on Abstract

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form.

No credit card required

What is RegEx?

RegEx is shorthand for "regular expression". It defines a pattern for searching or manipulating strings. For example, if you were looking for the word "gray", but wanted to search both possible spellings ("gray" and "grey") with one search, you could use the regular expression `«gr[ae]y» ` to search for both words at once.

How is RegEx Useful?

"So what?" you might be thinking. "Looks like some old-school database stuff."

Well, what if I told you that this regular expression `«\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b»` can be used to validate an email?. Imagine all the code it would take to validate an input as an email address without a regex string. Regex is a handy tool to keep in your toolkit as a web developer, especially its `-g` flag to check results globally.

Some other use cases where RegEx's string-matching capabilities can help:

  • Validate a domain name: ` $url = "http://abstractapi.com/"; if (preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $url)) { echo "Your url is ok."; } else { echo "Wrong url."; } `
  • Remove ~~repeated words~~ repeated words: ` $text = preg_replace("/s(w+s)1/i", "$1", $text); `
  • Find and print the information in the `<title> </title>` tag on a website: ` $fp = fopen("https://abstractapi.com","r"); while (!feof($fp) ){ $page .= fgets($fp, 4096); } $titre = eregi("<title>(.*)</title>",$page,$regs); echo $regs[1]; fclose($fp); `

Regex and JSON

Where is another place we see text in API development? The JSON file. We can validate API responses using Regex:

var body = JSON.parse(context.response.body);assert( body.transcript.search(/example.*/i) > -1, "transcript field does not contain 'faux'");

In this case, the RegEx is in parentheses behind `search`. We are looking for the word `example`, and the other characters in the parentheses are RegEx query parameters.

`.` means that `example` must be followed by at least one character.
`*` means that any number of characters can follow `example`.
`i` means that the search is not case sensitive.

If our query tells us the word `example` was not found, and `example` `was a resource we are depending upon, this test will tell us the resource is down.

Conclusion

RegEx is difficult to get into, but extremely powerful once it's understood, because it's like a programming language inside another programming language. You can even call it as an API.

Related API Terms

REST Client Everything you need to know about a REST Client. This article explains what a REST Client does, the four types of requests, and the REST Client request format.
API Integration Everything you need to know about API (aka Application Programming Interface) Integration. This article tells you what it is, what you can do with it, and more.
HTTP Request MethodsLearn what the HTTP Request METHODS are, as well as how and why they are used. Learn about PUT, POST, PATCH, and DELETE, plus HEAD and OPTIONS.

Get your free

API

key now

What is REGEX? Technical topics explained simply (6)

4.8 from 1,863 votes

See why the best developers build on Abstract

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form.

No credit card required

abstract

APIs tO LOOK UP

Weather APIMarket Data APIExchange Rate API

IPGeolocation APIPublic Holidays APICompany Enrichment APITime, Date, Timezone APILanguage Translation API

APIs tO CREATE

User Avatar APIWeb Scraping APILink Shortener API

Image Processing APIWebsite Screenshot API

APIs tO VALIDATE

IBANValidation APIEmailValidation API

Phone Validation API

RESOURCES

APIGlossaryFull APIListWhat's My IPAddress?HTTPStatus Code GuideEmail Regex Guide

IntegrationsAboutContactIntegrationsLegal

Status:

All systems normal

Abstract CSVAbstract PDFAbstract FilesAbstract Images

What is REGEX? Technical topics explained simply (8)

@2024 Abstract API Inc

Get your free

API

key now

What is REGEX? Technical topics explained simply (11)

4.8 from 1,863 votes

See why the best developers build on Abstract

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form.

No credit card required

What is REGEX? Technical topics explained simply (2024)

References

Top Articles
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 6510

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.