Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

[Tips] What is "regex" and why do the developer should to learn it?

Thursday 28 December 2017
|
Read: Completed in minutes

[Tips] What is "regex" and why do the developer should to learn it?

Regular expression is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager. The regex equivalent is .*\.txt.

What is regex and why do the developer should to learn it?



But you can do much more with regular expressions. In a text editor like Notepad++, you could use the regular expression \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b to search for an email address. Any email address, to be exact. A very similar regular expression can be used by a programmer to check if the user entered a properly formatted email address.

In just one line of code, whether that code is written in Perl, PHP, Java, a .NET language or a multitude of other languages.

Reference regex link: https://regexr.com/

For example:

Example one:
If you want to change all below value in your editor, you can do it easy with find regular expressions

I have below value as my text, I want to change all val="xxx" to xxx value.

val="4"
val="403"
val="200"
val="201"
val="116"
val="15"

Regular Expression
Find: .*"(\d+)"
Replace: $1

What is regex and why do the developer should to learn it?


Note
Remember check into Regular expression checkbox to notify Notepad++ search with regular expression

Result
4
403
200
201
116
15

Example two:

max, dog
lucy, dog
charlie, horse
molly, cat
buddy, cat
daisy, fish
lucky, nina
lucky, sun

Regular Expression
Find: ([a-z]+), ([a-z]+)
Replace: INSERT INTO Users (AccountName, RoleName) Values ('$1', '$2')

Result
INSERT INTO Users AccountName, RoleName Values 'max', 'dog'
INSERT INTO Users AccountName, RoleName Values 'lucy', 'dog'
INSERT INTO Users AccountName, RoleName Values 'charlie', 'horse'
INSERT INTO Users AccountName, RoleName Values 'molly', 'cat'
INSERT INTO Users AccountName, RoleName Values 'buddy', 'cat'
INSERT INTO Users AccountName, RoleName Values 'daisy', 'fish'
INSERT INTO Users AccountName, RoleName Values 'lucky', 'nina'
INSERT INTO Users AccountName, RoleName Values 'lucky', 'sun'

If you don't know regular expressions, you must change every line of it. If I have over 100.000 rows of it, that may take you many time to do it. So you should learn regular expression for understand the way how to use it!

Exmaple three:
(copyright +(©|\(c\)|©) +\d{4})( *[-,] *\d{4})* and replace with \1-2014 to update all copyright statements to 2014, regardless of the style of copyright symbol and the current copyright year. "copyright (c) 1996-2002

Reference:

The phrase regular expressions (and consequently, regexes) is often used to mean the specific, standard textual syntax (distinct from the mathematical notation described below) for representing patterns that matching text need to conform to. Each character in a regular expression (that is, each character in the string describing its pattern) is understood to be a meta character (with its special meaning), or a regular character (with its literal meaning).
For example, in the regex a. a is a literal character which matches just 'a' and . is a meta character which matches every character except a newline. Therefore, this regex would match for example 'a ' or 'ax' or 'a0'. Together, meta characters and literal characters can be used to identify textual material of a given pattern, or process a number of instances of it.

Pattern-matches can vary from a precise equality to a very general similarity (controlled by the meta characters). For example, . is a very general pattern, [a-z] (match all letters from 'a' to 'z') is less general and a is a precise pattern (match just 'a').

The metacharacter syntax is designed specifically to represent prescribed targets in a concise and flexible way to direct the automation of text processing of a variety of input data, in a form easy to type using a standard ASCII keyboard.

A very simple case of a regular expression in this syntax would be to locate the same word spelled two different ways in a text editor, the regular expression seriali[sz]e matches both "serialise" and "serialize". Wildcards could also achieve this, but are more limited in what they can pattern (having fewer meta characters and a simple language-base).

The usual context of wildcard characters is in globbing similar names in a list of files, whereas regexes are usually employed in applications that pattern-match text strings in general. For example, the regex ^[ \t]+|[ \t]+$ matches excess whitespace at the beginning or end of a line. An advanced regex used to match any numeral is [+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?. See the Examples section for more examples.

What is regex and why do the developer should to learn it?
What is regex and why do the developer should to learn it?
What is regex and why do the developer should to learn it?
What is regex and why do the developer should to learn it?
What is regex and why do the developer should to learn it?
What is regex and why do the developer should to learn it?
What is regex and why do the developer should to learn it?

Welcome your question and feedback, leave your comment, we can discuss about it!
Zidane




🙇🏼 We Appreciate Your Comments and Suggestions - Webzone - all things Tech Tips web development 🙇🏼
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com