DEV Community

kobecow
kobecow

Posted on

This is the time to check your knowledge of regex or Regular Expression

Why I wrote this article?

Because I googled regex again, and again.
I thought I needed to clarify what I know about parts of regex.
I will add my knowledge of regex in this post.

No.0 environment

useful web tool to test regex https://rubular.com/

sample sentences from Wiki https://en.wikipedia.org/wiki/Computer.
In this case, using first two paragraphs.

A computer is a machine that can be instructed to carry out sequences of arithmetic or logical operations automatically via computer programming. Modern computers have the ability to follow generalized sets of operations, called programs. These programs enable computers to perform an extremely wide range of tasks. A "complete" computer including the hardware, the operating system (main software), and peripheral equipment required and used for "full" operation can be referred to as a computer system. This term may as well be used for a group of computers that are connected and work together, in particular a computer network or computer cluster.

Computers are used as control systems for a wide variety of industrial and consumer devices. This includes simple special purpose devices like microwave ovens and remote controls, factory devices such as industrial robots and computer-aided design, and also general purpose devices like personal computers and mobile devices such as smartphones. The Internet is run on computers and it connects hundreds of millions of other computers and their users.

No.1 Global match

Global match means to return not only first match word or char also others.

ie.
search in in sample text.
Below code written in JavaScrip.

const sample_text = "A computer is a machine ...";// <-- must include whole sample sentences.
console.log(sample_text.match(/in/g));
/*
// return
[
  'in', 'in', 'in',
  'in', 'in', 'in',
  'in', 'in', 'in',
  'in', 'in'
]
*/

To be continued

Top comments (0)