Is the iPhone really worth the price?

If you have an older Apple phone, then I’m sure you have noticed that shortness of battery life, or the crashing of different apps every so often to send you to your local CSpire, Verizon, and/or…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Applicability

Regex is short for Regular Expression, and while that clarifies the abbreviation, this amalgamated grouping of symbols initially looks more like an alien language than a “regular” expression.

Simply said, regex is a pattern to be used in a search. Regex can be used to create very useful searches, particularly when you are searching for more than one thing or variations of one thing, or when validating the criteria of an input, such as a password or email address.

My first encounter with regex happened after a google search for how to split a string using multiple characters. While my initial response was some confusion, I quickly saw that once you break a regex down into its individual characters, it’s somewhat simple.

At the most basic level, a regex should begin and end with ( / ) forward slashes and the search criteria will be between these two slashes.

To demonstrate, let’s break down the regex in the title of this post: /\.|\?|\!/

As you can see, this repetitious code is simply searching for three types of punctuation. This regex could be utilized for counting the number of sentences in an article; to include statements, exclamations and questions.

Here’s a few terms and characters to cover some basic concepts in regex.

Major component definitions:

literal: a character we’re literally trying to find in the search or matching expression

metacharacter: a character that is not a literal and that has a special meaning

target string: the string we’re searching for our pattern in

escape sequence: allows us to use a metacharacter as a literal by placing a (\) backslash in front of it

A few common character definitions:

( * ) asterisk: match the character(s) before the *

( + ) plus: repeat the character before the +

( {n} ) curly braces: repeat the character before the curly braces for n number of times.

( . ) dot: a wildcard, can be used in place of any other symbol

( ? ) question mark: optional indicator, the preceding character may or may not appear in the match

( ^ ) caret: indicates the match at the beginning of a string

( $ ) dollar: indicates the match at the end of a string

( \d ) digit character: match a digit [0–9]

( \s ) white space character: match any space, tab, or line feed

Regex is used in many programming languages

Regex is applicable in a wide range of languages, including PHP, Javascript, Ruby, Perl, Swift, Python and others, but it’s important to note that while much of the character usage will be valid regardless of the particular language, it’s not a universal guarantee. Likewise, these differences aren’t something that our friend google can’t help us navigate.

This post only scrapes the surface of regex, but there’s bountiful internet posts available to build on these basics.

There are also many websites that will allow you to test your regex on a test string. These websites are typically tailored to a specific programming language, so be sure to choose one that fits you needs.

Regex is a useful and powerful tool to use in programming languages. There are many options for how to compile your regex search pattern, so I encourage you to try it out. Google ‘regex’ for your programming language and start deciphering those symbols!

Fry getting ready for regex!

Add a comment

Related posts:

What to do when you feel like a fraud

As a writer in the areas of self-improvement, personal growth, minimalism, and positivity (to name a few), it’s important to me to Failure #1: I’ve been spending money like it grows on trees right…

The Temporal Singularity

Herein lies the destiny of all sorrow fear mutated from something to another, reality of a four-dimensional frame twisted birth and death, the infinite spiral retained. The undoing of all things…

How to create a BitBucket repository using BitBucket API?

Bitbucket like we all know is a web-based version control repository hosting service owned by Atlassian. Everything that could be done using the web console is also made available using the Bitbucket…