大家是如何学习正则表达式的?或者有什么学习的建议?

你猜他在干嘛?

— My reply:

I am guessing you are try to find this string

lkjciidsofwopvqi-something

in this string long string

flkjciidsofwopvqi-something

But I got:

Debugger entered--Lisp error: (invalid-read-syntax ") or . in a vector")
  read(#<buffer *scratch*>)
  elisp--preceding-sexp()
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

Looks like I am missing some context here.


This is my learning:

  • matches two or more blank lines in sequence.

(re-search-forward "^\n\\{2,\\}")

  • match TODO

(re-search-forward "\\[TODO\\](\\([^\\)]+\\))" nil t)

  • match UUID

(re-search-forward "PDFNAME::\\([a-zA-Z0-9 \.\_\,\-]+\\)\.pdf - " nil t)

  • match page number

(re-search-forward "PAGENUM::\\([0-9]+\\)::END" nil t)

  • match secrete

(re-search-forward (concat arg "::\\(.*\\)"))

  • match @dfn{xxx}

(re-search-forward "@dfn{\\([^}]+\\)}" nil t)

  • match end sentence

(re-search-forward "[\.,;:!\?]" end t)


If you know python: and interested in nCoV:

    overall_information = re.search(r'\{("id".*?)\]\}', str(soup.find('script', attrs={'id': 'getStatisticsService'})))
    province_information = re.search(r'\[(.*?)\]', str(soup.find('script', attrs={'id': 'getListByCountryTypeService1'})))
    area_information = re.search(r'\[(.*)\]', str(soup.find('script', attrs={'id': 'getAreaStat'})))
    abroad_information = re.search(r'\[(.*)\]', str(soup.find('script', attrs={'id': 'getListByCountryTypeService2'})))
    news = re.search(r'\[(.*?)\]', str(soup.find('script', attrs={'id': 'getTimelineService'})))

if you intersted in bash

find xxx from grep_xxx

$(grep -oP '(?<=aoa_)[0-9]+' tmp)


inspired by @manateelazycat

@Action


why github is unhappy with rep name regexp? Possible related to their reg engine?

  • oh my god, why regexp is everywhere…

  • proudly power by org-mode