正则表达式的一些高级用法

  1. 不允许出现某个单词,使用?!
    (?!Pattern).\.matches
    表示.matches之前的不能是Pattern
  2. 非贪婪匹配,在匹配项后加?
    matches\((.*?)\)
    这里在.*后加问号,表示尽可能少的匹配。
  3. \w表示字母、数字和下划线
  4. 防范redos攻击,可使用Cyber-Redos-Terminator检查开发使用的正则表达式。java代码里排查可能的redos攻击,可使用下面三个正则式:
python 复制代码
    REG_CALL_PAT1 = re.compile("Pattern\\.compile\\((.*)\\)")
    REG_CALL_PAT2 = re.compile("Pattern\\.matches\\((.*),.*\\)")
    REG_CALL_PAT3 = re.compile('(?!Pattern).\\.matches\\((".*"|[\\w\\.]+)\\)')
相关推荐
2401_8274999911 小时前
python项目实战11-正则表达式基础
python·mysql·正则表达式
互联网散修11 小时前
零基础鸿蒙应用开发第三十三节:正则表达式基础与应用
华为·正则表达式·harmonyos
bukeyiwanshui13 小时前
20260414 正则表达式及shell三剑客
数据库·mysql·正则表达式
坐吃山猪1 天前
Python09_正则表达式
开发语言·python·正则表达式
橙露2 天前
Python 正则表达式:文本清洗与信息提取速通手册
python·正则表达式·easyui
XiaoQiao6669994 天前
pytnon中正则表达式小题详解
python·正则表达式
gCode Teacher 格码致知4 天前
Python基础教学:正则表达式中的忽略大小写以及符号“-“的问题-由Deepseek产生
python·正则表达式
ths5125 天前
Python 正则表达式实战指南:从入门到精通(12 个高频案例)(三)
python·正则表达式
ths5125 天前
Python 正则表达式学习笔记(小白超详细版)(一)
python·正则表达式
kcuwu.7 天前
Python 正则表达式从入门到实战
数据库·python·正则表达式