Skip to main content

regex: Using notepad++

Goal: Learn and practice regex

. : zero or one character

[wildcards]
. : any character (t.p matches tip, top, tap...)
* : zero or more times (.* matches all letter in 'tip')
? : zero or one time (tips? matches 'tip' or 'tips' - with s or without s)
+ : one or more times (tip.+ matches tips but not tip)
x|y : x or y (tip|top match both tip or top)
\ : escape any special character (where\? matches where?
[Anchors]
^ : start of a string (^T matches 'This is an example.')
$ : end of a string ($s matches 'There are many users')
[Groups]
[x|X] : matches either x or X ([C|c]at matches Cat or cat)
{n} : matches n number of times (.{3} matches The in There - 3 characters)

Real life example: Each line, remove everything except e-mail address


Line 1: era@gmail.com
Line 22: zeo0326@gmail.com
Line 39: ro97xu@gmail.com
Line 95: zeroday224@gmail.com
Line 1002: dhs@gmail.com
Line 50044: aint@gmail.com
Line 61345: se7en@gmail.com
Line 7893465: tn@gmail.com

Use notepad++ freeware.

Dùng tính năng tìm kiếm và thay thế (Ctrl + H)
PHẢI chọn Regular expression trong phần Search Mode


Find what: "^.*(\<[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z][A-Za-z][A-Za-z]?[A-Za-z]?\>).*$" (không nhập dấu nháy kép)
Replace with: \1

Thử nghiệm trước để kiểm tra:
Nhấn FindFind Next vài lần để xem có tìm đúng nội dung cần xóa không.

Nhấn Replace All


Commonly used "patterns" in search/replace


- Email address: [A-Z0-9._%+-]+@[A-Z0-9.-]{3,65}\.[A-Z]{2,4}
- Search for emails ending with .vn or .com: [^\.vn][^\.com]$




Example: "${Keep everything inside}"

Search: "\$\{(.*[^{"\}])\}\"

Replace: \1

provider "oci" {
  region           = "${var.region}"
  tenancy_ocid     = "${var.tenancy_ocid}"
  user_ocid        = "${var.user_ocid}"
  fingerprint      = "${var.fingerprint}"
  private_key_path = "${var.private_key_path}"
}

Regex functions in Google Sheet

REGEXMATCH

REGEXREPLACE

REGEXEXTRACT

Regex functions in Microsoft Excel

New Regular expression (Regex) functions in Excel

REGEXTEST: Checks if any part of supplied text matches a regex pattern.

REGEXEXTRACT: Extracts one or more parts of supplied text that match a regex pattern.

REGEXREPLACE: Searches for a regex pattern within supplied text and replaces it with different text.

Resources

>>> https://regex101.com/

>>> https://regexr.com

Popular posts from this blog

Linux command: lspci

Linux command: lspci - list pci devices tuyendq@ubuntu001:~$ man lspci NAME        lspci - list all PCI devices SYNOPSIS        lspci [options] DESCRIPTION        lspci is a utility for displaying information about PCI buses in the system and devices connected to them.        By  default,  it  shows a brief list of devices. Use the options described below to request either a more verbose output or output intended for parsing by        other programs.        If you are going to report bugs in PCI device drivers or in lspci itself, please include output of "lspci -vvx" or even better  "lspci  -vvxxx"  (however,        see below for possible caveats).        Some  parts of the output, especially in the highly verbose modes, are probably intelligible only to experienced PCI hac...

The Amazon Product Advertising API

What is the Amazon Product Advertising API?

Java: Free Online Courses

The Java™ Tutorials by Oracle The Java Tutorials are practical guides for programmers who want to use the Java programming language to create applications. They include hundreds of complete, working examples, and dozens of lessons. Groups of related lessons are organized into "trails". https://docs.oracle.com/javase/tutorial/ Learn to Program in Java at edX.ogr Get started on the path to becoming a software engineer by learning core coding skills in Java—one of the most popular programming languages. https://www.edx.org/course/learn-to-program-in-java-0 Java Tutorial by javapoint.com https://www.javatpoint.com/java-tutorial Java Tutorial by SoloLearn.com I love SoloLearn because I can learn Java - and other popular programming languages - anywhere, any time on your mobile devices. https://www.sololearn.com/Course/Java/ Java on Azure https://docs.microsoft.com/en-us/learn/paths/java-on-azure/