Text Replace

10
Characters: 0
Characters: 0
Match: 0

Learn the way to replace text with Regular expressions

Summary (TL;DR)

Here's a description of this simple application that searches and replaces strings and text. After that, we'll briefly discuss the importance of regular expressions in search and replace.

Search and Replace Text

Background

Search and replace text and strings are common in work and office work, and if you're an IT savvy person, you can use regular expressions in an appropriate editor, find and run programs, or write simple programs yourself in Python and other languages. Depending on the nature of your job, you may need to perform complex tasks such as processing big data and statistics like a data scientist.

This article is intended for non-engineers and those who are just starting out. Those who stare at the screen when searching for data, print it out and count it, or use the search function to follow one keyword at a time. When you want to replace them, you have to erase them one by one, rewrite them, or paste them. Each one is small, but I think it's often disgusting in number. However, if you are not careful, you may make a simple mistake and it may become embarrassing.

First of all, I hope you know that there is an easy way to do it with the features in this article. Beware, you may get stuck in the swamp after that.

Boring tasks

How to use

  1. Enter the text in the input field. Longer sentences are fine. If the height of the input column is not high enough, you can adjust it with the slider at the top. Also, if you want to erase at once, please push the x button at the right end of the slider.

  2. Enter the content you want to find or replace. It shows the most commonly used conditions in advance as tags, which you can select by clicking on them.

  • Whether "Aa" is case-sensitive or not. When checked, it is case-sensitive.
  • Whether "*" uses a regular expression or not. If you check this box, you will be in regular expression mode.
  • Whether "👀" disables this condition or not. Checking this box will invalidate the condition you have entered.
  • If you don't need it, delete it with the "x" button.
  • If you want to minimize it, you can minimize it by clicking on the "{\fnDroid}" button.
  • The number of matches is displayed at the bottom of the page.
  • You can specify a number of search and replace conditions.
  1. the substituted results are displayed in the lower text area in real time. Copying to the clipboard is also done with the push of a button.

Regular Expression

Regular expressions are a very powerful tool. Knowing or not knowing this can make at least a tenfold difference in the efficiency of your work. As an introduction to regular expressions, the following articles are very helpful.

Regular Expression Language - Quick Reference : Microsoft Build

You can easily understand how to work Regular expression with the following site.

Regexr.com

We'll use the regular expressions provided in advance by this feature to explain this.

What is a regular expression in the first place? There are many definitions, but for now, I'll simply say "a technique to clean up a string of various patterns at once". It's not the right phrase at all, but I think it's enough for an introductory sense. This is because if you have an idea of when regular expressions can be used and how practical they are, you will be reminded to use them when you need them.

Typically, when you search, you enter the word you want to search for. It's "search" and "introductory. The same goes for regular expressions, but they have special characters and grammars that make them easier to clean up in one go. Combine these and you'll be able to put them away in one fell swoop. Only the most commonly used ones are listed below.

Special CharDescriptionExMatch
.any 1 char.Z
+The character immediately preceding it is repeated one or more times.A+AAA
*The character immediately preceding it is repeated zero or more times.AB*AAA
?The character immediately preceding it is repeated zero or one.AB?AABA
|ORAA|BBAA
[...]Match any one of the letters in parentheses[123]3
(...)Putting the parentheses together as a groupa(bc)abc
{n,m}Specify the min and max number of repeat of the preceding character.A{3,5}AAA
\tTab
\nLine break
\sBlank
\dNumber
\DExcept number
\walphabet, _, number
^Line head^abaaba...
\$Line tailend\$the end

Description of the prepared samples

  • Continuous blanks (2 or more blanks)

    \s{2,}
  • Blank at the line head

    ^\s+
  • Blank at the line tail

    \s+$
  • Empty line break(Start with and End with line break)

    ^\n$

Technology

  • Regular expression

    • Definition of Regular Expression(Javascript)

      let re = /ab+c/;
      
      let re = new RegExp("ab+c");
    • Is there a matching case?

      let re = /ab+c/;
      re.test("abbbbbbbbbbbc");
      // -> true
      
      re.test("ac");
      // -> false
    • Replace with the matching case.

      let re = new RegExp("ab+c", "gm");
      "abbc is wrong. ac is right. abbbbbbbc!".replace(re, "He");
      // -> "He is wrong. ac is right. He!"

Finally

It is very simple. I hope I can be of some help to you.

Updated at: Thu Jun 11 2020

© 2020-presentTerms|Privacy