python regex note

  To remember python regex easily, we organise python regex notes from concrete to abstract, and from simple to sophisticated.

I, Important character:

  1, Quantitive character:

    ? :[0,1],   *:[0,infi),  +:(0,infi),  {n}:[n rep],  {m,}:[m, infi),  {,n}:[0,n],  {m,n}:[m,n],  

    ? (nogreedy option)

  2, Begin and End:

     ^: beginning,   $: ending

  3, Making own character class:

    [abc]  ,[^abc]: ^ rep non
  4, Character classes:

     \d,\D,\s,\S,\w,\W
  5: dot (or wildcard) character:

    . ,   .*,  (.*) ? : rep nongreedy fashion

II, Usefull regex arguments

  1, re.DOTALL : match all characters, including the newline character.

  2, re.I (re.IGNORECASE): ignore uppercase 

  3, re.VERBOSE : spread the regex over multiple lines with comments.

  4, | : we could use pipe character to cobine all three above arguments.

III, generate regex procedure:

  1, regex = re.compile(r"")

  2.1.1, regex.search("")

  2.1.2, regex.search("").group(), (or regex.search("").group(No.)),  greedy defalut

  2.2, regex.findall("")

  2.3 regex.sub("")

  3 , re.compile(r‘‘‘(

          

            )‘‘‘, re.VERBOSE) : to manage more complex regrexes.

 


6: re.DOTALL, re.I

时间: 2024-12-26 01:38:35

python regex note的相关文章

Python Function Note

Python Function Note 1 #汉诺塔问题Python实现 2 def my_move(n, a, b, c): 3 if n == 1: 4 print(a + ' --> ' + c) 5 else: 6 my_move(n-1, a, c, b)#将前n-1个盘子从a放到b 7 my_move(1, a, b, c)#将最下面的盘子从a放到c 8 my_move(n-1, b, a, c)#将b上的n-1个盘子放到c上 9 return 1 #杨辉三角Python实现 2

#MySQL for Python(MySQLdb) Note

#MySQL for Python(MySQLdb) Note #切记不要在python中创建表,只做增删改查即可. #步骤:(0)引用库 -->(1)创建连接 -->(2)创建游标 -->(3)选择数据库 -->(4)执行语句 -->(5)关闭连接 #(0)引用库 import MySQLdb #(1)创建连接 con = MySQLdb.connect(user = "root", passwd = "123456",host =

Python - Learn Note (2)

Python基本数据类型 整数.浮点数(浮点数也就是小数,之所以称为浮点数,是因为按照科学记数法表示时,一个浮点数的小数点位置是可变的).字符串(字符串是以''或""括起来的任意文本).布尔值.空值(空值是Python里一个特殊的值,用None表示) print语句 print语句也可以跟上多个字符串,用逗号","隔开,就可以连成一串输出,遇到逗号","会输出一个空格:使用"+"拼接不会产生空格 Python注释 Python

python basic note

偶尔用Python做点事情,用的时候隔了许久,又不太记得了,有时连基本的语法都忘掉,这里记录在一张纸上,方便查看.也涵盖比较实用的内容,方便信手捻来(我没写错吧) 其中代码片段主要摘自前段时间写的一些Python代码. Python Help >>> python("subprocess") 帮助是很重要,linux程序员,你懂的 Python tutorial https://docs.python.org/2/tutorial/ 初学Python的人用这个好,计算

Python - learn note(1)

1. 下载安装Python 2.7(为了向下兼容以前的版本), Python 3.5(VS2015不支持配置3.6的环境) 教程 需要使用VS2015进行开发,必须勾选上后面两项: 2. VS2015开发Python Visual Studio集成了Python Tools for Visual Studio插件.我们只需要在自定义安装的时候点选安装即可.--配置开发环境 修改文件保存编码方式: 3.交互模式 :?根据主提示符(">>>")来执行命令 从属提示符(&q

python regex

re.match: match from the beginning of the string re.search: scan through the whole string to find a match dash '-' inside square '[]' means a range. put dash in the end to just match a dash

Python manual note

This variable should be treated as read-only by the user. Don’t explicitly assign a value to it — you would create an independent local variable with the same name masking the built-in variable with its magic behavior.

【翻译】Python标准模块库之-------Subprocess

原文来自官网文档:https://docs.python.org/2.7/ 17.1. subprocess — Subprocess management New in version 2.4. The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends

Windows API Hooking in Python

catalogue 0. 相关基础知识 1. Deviare API Hook Overview 2. 使用ctypes调用Windows API 3. pydbg 4. winappdbg 5. dll injection 6. process monitor with WMI 7. sobek-hids 0.  相关基础知识 0x1: Python 程序和 C 程序的整合 为了节省软件开发成本,软件开发人员希望能够缩短的软件的开发时间,希望能够在短时间内开发出稳定的产品.Python 功能强