regular expression

Jmeter 兵器谱之 Regular Expression Extractor 在 Apache JMeter 中,除了传统的 Timer、BeanShell PreProcessor 和 PostProcessor 等元件外,还有一个非常强大且常被忽视的元件:Regular Expression Extractor。正则表达式提取器是一个可以从响应中提取特定格式的文本的元件。它可以用于从复杂的响应数据中获取有用的信息,例如 API 返回的 JSON 或 XML 数据。 阅读详情

 

今天学习了perl的正则表达式,它重要吗?已经很久没有用过了,但是需要的时候就急了,因为每次用过就仍了,没有好好的理解过。
regular expression' world is full of interesting. believe that and study it in the core.

regular expression帮助我们match、replace文本。

我将regular expression 分为三部分,search patterns,replacement patterns,opreator

 

1 search patterns告诉我们怎么去match

1).*^${n,m}()[]

2)/w/W/s/S/d/D

 

2 replacement patterns告诉我们将匹配的内容做如何处理

 

 

3 opreator其实与regular expression无关,他与perl相关。

m// (Matching)

s/// (Substitution)

split

另外perl常用的是基于命令行格式,如perl -ne ‘s///ig’ file.txt

n代表在while(<>)循环

e代表命令行格式

 

 

 

1.3.2.1 Search patterns

The characters in the following table have special meaning only in search patterns:

Character

Pattern

.

Match any single character except newline. Can match newline in awk.

*

Match any number (or none) of the single character that immediately precedes it. The preceding character can also be a regular expression. For example, since . (dot) means any character, .* means "match any number of any character."

^

Match the following regular expression at the beginning of the line or string.

$

Match the preceding regular expression at the end of the line or string.

/

Turn off the special meaning of the following character.

[ ]

Match any one of the enclosed characters. A hyphen (-) indicates a range of consecutive characters. A circumflex (^) as the first character in the brackets reverses the sense: it matches any one character not in the list. A hyphen or close bracket (]) as the first character is treated as a member of the list. All other metacharacters are treated as members of the list (i.e., literally).

{n,m}

Match a range of occurrences of the single character that immediately precedes it. The preceding character can also be a metacharacter. {n} matches exactly n occurrences; {n,} matches at least n occurrences; and {n,m} matches any number of occurrences between n and m. n and m must be between 0 and 255, inclusive.

/{n,m/}

Just like {n,m}, but with backslashes in front of the braces.

/( /)

Save the pattern enclosed between /( and /) into a special holding space. Up to nine patterns can be saved on a single line. The text matched by the subpatterns can be "replayed" in substitutions by the escape sequences /1 to /9.

/n

Replay the nth sub-pattern enclosed in /( and /) into the pattern at this point. n is a number from 1 to 9, with 1 starting on the left.

在perl regularEX中在()中的内容可以是一个group,也可以将其中匹配内容保存在一个变量中,变量名可以在serach pattern中使用,也可以在replacement pattern中使用。

/< />

Match characters at beginning (/<) or end (/>) of a word.

+

Match one or more instances of preceding regular expression.

?

Match zero or one instances of preceding regular expression.

|

Match the regular expression specified before or after.

( )

Apply a match to the enclosed group of regular expressions.

/w

Word character

/W

Non-word character

/d

Digit character

/D

Non-digit character

/s

Whitespace character

/S

Non-whitespace character

 

 

 

1.3.2.2 Replacement patterns

The characters in the following table have special meaning only in replacement patterns:

Character

Pattern

/

Turn off the special meaning of the following character.

/n

Restore the text matched by the nth pattern previously saved by /( and /). n is a number from 1 to 9, with 1 starting on the left.

&

Reuse the text matched by the search pattern as part of the replacement pattern.

~

Reuse the previous replacement pattern in the current replacement pattern. Must be the only character in the replacement pattern (ex and vi).

%

Reuse the previous replacement pattern in the current replacement pattern. Must be the only character in the replacement pattern (ed).

/u

Convert first character of replacement pattern to uppercase.

/U

Convert entire replacement pattern to uppercase.

/l

Convert first character of replacement pattern to lowercase.

/L

Convert entire replacement pattern to lowercase.

/E

Turn off previous /U or /L.

/e

Turn off previous /u or /l.

 

 

 

 

1.3.2 Regular Expression Operators

Perl provides the built-in regular expression operators qr//, m//, and s///, as well as the split function. Each operator accepts a regular expression pattern string that is run through string and variable interpolation and then compiled.

Regular expressions are often delimited with the forward slash, but you can pick any non-alphanumeric, non-whitespace character. Here are some examples:

qr#...#       m!...!        m{...}
s|...|...|    s[...][...]   s<...>/.../

A match delimited by slashes (/.../) doesn't require a leading m:

/.../      #same as m/.../

Using the single quote as a delimiter suppresses interpolation of variables and the constructs /N{name}, /u, /l, /U, /L, /Q, /E. Normally these are interpolated before being passed to the regular expression engine.

qr// (Quote Regex)


qr/PATTERN/ismxo

Quote and compile PATTERN as a regular expression. The returned value may be used in a later pattern match or substitution. This saves time if the regular expression is going to be repeatedly interpolated. The match modes (or lack of), /ismxo, are locked in.

m// (Matching)


m/PATTERN/imsxocg

Match PATTERN against input string. In list context, returns a list of substrings matched by capturing parentheses, or else (1) for a successful match or ( ) for a failed match. In scalar context, returns 1 for success or "" for failure. /imsxo are optional mode modifiers. /cg are optional match modifiers. /g in scalar context causes the match to start from the end of the previous match. In list context, a /g match returns all matches or all captured substrings from all matches. A failed /g match will reset the match start to the beginning of the string unless the match is in combined /cg mode.

s/// (Substitution)


s/PATTERN/REPLACEMENT/egimosx

Match PATTERN in the input string and replace the match text with REPLACEMENT, returning the number of successes. /imosx are optional mode modifiers. /g substitutes all occurrences of PATTERN. Each /e causes an evaluation of REPLACEMENT as Perl code.

split


split /PATTERN/, EXPR, LIMIT
split /PATTERN/, EXPR
split /PATTERN/
split

Return a list of substrings surrounding matches of PATTERN in EXPR. If LIMIT, the list contains substrings surrounding the first LIMIT matches. The pattern argument is a match operator, so use m if you want alternate delimiters (e.g., split m{PATTERN}). The match permits the same modifiers as m{}. Table 1-8 lists the after-match variables.

 

 

1.3.4 Examples
Example 1-1. Simple match
# Match Spider-Man, Spiderman, SPIDER-MAN, etc.
my $dailybugle = "Spider-Man Menaces City!";
if ($dailybugle =~ m/spider[- ]?man/i) { do_something(  ); }
Example 1-2. Match, capture group, and qr
# Match dates formatted like MM/DD/YYYY, MM-DD-YY,...
my $date  = "12/30/1969";
my $regex = qr!(/d/d)[-/](/d/d)[-/](/d/d(?:/d/d)?)!;
if ($date =~ m/$regex/) {
  print "Day=  ", $1,
        "Month=", $2,
        "Year= ", $3;
}
Example 1-3. Simple substitution
# Convert <br> to <br /> for XHTML compliance
my $text = "Hello World! <br>";
$text =~ s#<br>#<br />#ig;
Example 1-4. Harder substitution
# urlify - turn URL's into HTML links
$text = "Check the website, http://www.oreilly.com/catalog/repr.";
$text =~ 
    s{
      /b                         # start at word boundary
      (                          # capture to $1
       (https?|telnet|gopher|file|wais|ftp) : 
                                 # resource and colon
       [/w/#~:.?+=&%@!/-] +?     # one or more valid
                                 # characters 
                                 # but take as little as
                                 # possible
      )
      (?=                        # lookahead   
        [.:?/-] *                #  for possible punctuation
        (?: [^/w/#~:.?+=&%@!/-]  #  invalid character
          | $ )                  #  or end of string
      )
     }{<a href="$1">$1</a>}igox;
 
Any word (a word is defined as a sequence of alphanumerics - no whitespace) that contains a
 double letter, for example "book" has a double "o" and "feed" has a double "e". 
 
/([a-zA-Z])/1/注意这里的/1,他代表了前面()中匹配的内容  

 

RegEx报错“Invalid regular expression“的转义字符处理 在使用正则表达式时,Invalid regular expression错误常由转义字符处理不当引起。本文分析了该问题的成因,并提供了解决方案。主要问题包括双重转义和语言特定的转义规则。解决方案包括使用原始字符串标记、显式双重转义以及利用特殊字符转义表。文章还提供了实战案例和跨语言转义对照表,建议优先使用原始字符串、添加注释说明转义逻辑、利用测试工具和转义函数。通过这些方法,用户可以系统性解决正则表达式的转义相关错误。 阅读详情

相关推荐

UE4入门实例17(Unreal制作卡通Post Process材质球)

效果展示 #1 创建Post Porcess材质球 #2 编写Shader功能 #3 设置场景区域内风格化渲染 #1 创建Post Porcess材质球 #2 编写Shader功能 创建基础效果 移除现有通道渲染 设置视图渲染范围 #3 设置场景区域内风格化渲染 #4 加群下载Shader源码:284105567 ...

Unity3d 攻城师一枚 1351

Linux操作系统中vi无法输入中文的原因, E35: No previous regular expression

用一句话概括原因以及解决方法的话: 就是默认vi进去的是命令模式,你需要通过在键盘输入“i,a,o”随便一个英文进入编辑模式,然后按一下shift键切换为中文就行了。 (适用于不知道怎么切换中文,以及适用于看到输入的中文,按回车键却没有中文输入进去的情况) 1.首先我们在终端执行 ‘’vi test‘’命令时,默认打开test文件(若没有则会自动创建) 此处我已经在test文件里面编辑了一些内容了: 2.接着我们处于的是vi工作模式(一共有命令模式,编辑模式,命令项模式或底行模式.

weixin_50746407的博客 1万+

RAGFlow源码解析-2、从源码构架ragflow v0.25.0镜像

本文详细记录了从零开始构建自定义RAGFlow镜像lt/ragflow:0.25.0的全过程。首先介绍了环境准备,包括检查Node.js、Docker版本和项目结构。然后详细说明了构建步骤:编译前端、创建自定义Dockerfile、构建镜像和验证。接着讲解了docker-compose配置修改要点,包括网络定义、MySQL依赖处理等。最后总结了部署过程中遇到的五个关键问题及解决方案,包括networks未定义、MySQL服务依赖、tiktoken文件缺失、数据库配置错误和端口映射问题。通过完整的操作流程和问

liutao841204的专栏 367

正则表达式(Regular Expression)基本概念及理解

正则表达式(Regular Expression) 正则表达式(regular expression)描述了一种字符串匹配的模式(pattern),可以用来检查一个串是否含有某种子串、将匹配的子串替换或者从某个串中取出符合某个条件的子串等。 构造正则表达式的方法和创建数学表达式的方法一样。也就是用多种元字符与运算符可以将小的表达式结合在一起来创建更大的表达式。正则表达式的组件可以是单个的字符、字符集合、字符范围、字符间的选择或者所有这些组件的任意组合。 正则表达式是由普通字符(例如字符 a 到 z)以及特殊

X1nZz的博客 4873

天线学习笔记——串馈网络设计

工程中通常更倾向于使用50Ω、70.7Ω、100Ω的固定阻抗的带宽,实际中可以分别使用固定阻抗的带宽和计算得到的带宽进行仿真,观察二者的性能,取性能更优者即可。本系列是一个记录天线设计的笔记,分享出来也希望能够帮助到大家,后续本系列文章还会不定期更新,如有需要可关注,任何问题均可在评论区或私信提出,看到必回。如果对大家有帮助可进行打赏哦~

Ethan的博客 7895

rv1126平台spi屏调试

st7789v2 i2c调试

zuoanyouzhuan_的博客 2041

vim E35: No previous regular expression

找到 ~/.viminfo文件,然后sudo chmod 777 viminfo,问题解决!

weixin_41678668的博客 1万+

Cloud Connector RFC 访问控制深度实践:为 SAP BTP ABAP environment 打通安全、可控的远程连接

本文是一份面向企业ABAP团队与平台工程团队的Cloud Connector RFC访问控制配置指南。文章详细介绍了虚拟主机/实例号、负载均衡、资源白名单等核心概念,并提供了从零开始的配置流程。主要内容包括:通过Cloud Connector建立安全隧道的价值(零暴露、最小权限)、两种连接类型(无负载均衡/带负载均衡)的配置方法、资源白名单设置技巧,以及两个典型应用场景(Custom Code Migration远程检查与BAPI调用)的实操案例。指南基于SAP官方文档,包含落地经验与避坑建议,可帮助团队快

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 149

正则表达式Regular expression

Ⅰ. 简介 正则表达式(regular expression)是一种字符串匹配模式或者规则,它可以用来检索、替换那些符合特定规则的文本。正则表达式几乎适用于所有编程语言,无论是前端语言 JavaScript,还是诸如许多后端语言,比如 Python、Java、C# 等,这些语言都提供了相应的函数、模块来支持正则表达式,比如 Python 的 re 模块就提供了正则表达式的常用方法。 Ⅱ. 正则表达式语法 1) 元字符 正则表达式元字符 元字符 匹配内容 . 匹配除换行符以外的任

noobiee的博客 1252

玩转企业微信群机器人:一份超详细的Webhook消息推送指南

企业微信群机器人是一个连接内部协作与外部服务的强大桥梁。通过灵活运用本文介绍的各种消息类型,你可以构建出丰富多彩、信息明确的自动化通知系统,极大地提升团队沟通效率。现在,就动手试试,将你的第一个机器人集成到工作流中吧!如果你有任何有趣的机器人应用场景或遇到了问题,欢迎在评论区留言交流!

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 3984

全面认识PFC和LLC

想象一下,你在拉一辆车,如果你的力气都用在推动车子前进的方向上,这样拉车会比较轻松。而如果你的力气用在不正确的方向,比如侧向、斜向,那就需要更大的力气才能推动车子。PFC就是在帮助电流“朝着正确的方向”流动,这样可以用更少的能量做更多的事情,减少无用的功率损耗。PFC负责将电流方向对齐,让电源效率更高,而LLC负责电压的高效转换,两者配合可以在更宽的负载范围内保持高效率。综上所述,PFC LLC电路是一种高效的电源转换电路,通过PFC模块和LLC模块的组合,实现了从交流电到直流电的高效转换。

weixin_43199439的博客 6141

正则表达式(Regular Expression)详解

正则表达式详解 正则表达式实例详解

qq_41768644的博客 919

RTA_OS基础功能讲解 2.6-资源锁和自旋锁

访问需要在任务和 ISR 之间共享的硬件或数据可能不可靠、不安全。这是因为当优先级较低的任务或 ISR 正在更新共享数据时,可能会发生任务或 ISR 抢占。这种情况被称为竞争条件,极难测试。访问共享数据的语句序列称为关键部分。要安全访问关键部分中引用的代码和数据,就需要执行互斥。换句话说,必须确保系统中没有其他任务或第 2 类 ISR 能够在关键部分期间抢占正在执行的任务。你可以将任务声明为非抢占式任务,这样就可以避免互斥问题。

本博客专注于嵌入式软件领域技术分享。 293

Regular Expression Decoder:高效解析复杂文本的利器

Regular Expression Decoder:高效解析复杂文本的利器 在现代软件开发中,处理和解析文本数据是一项常见且关键的任务。特别是在金融、数据分析和日志处理等领域,高效且准确的文本解析工具至关重要。今天,我们将介绍一个强大的开源项目——Regular Expression Decoder,它能够帮助开发者利用正则表达式快速构建对象,从而简化复杂文本数据的处理流程。 项目介绍 Regu...

gitblog_00955的博客 1017

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Wildcard Matching & Regular Expression Matching & KMP

觉得Wildcard Matching & Regular Expression Matching & KMP都是字符串匹配问题,所以想把它们放一起 方法有动态规划、回溯、有限自动机 一、Wildcard Matching: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches

沉浸如海 633

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Regular Expression

Regular Expression: NFA:

UniversityGrass的博客 169

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

Eclipse Regular Expression Tester

http://brosinski.com/regex/ RegEx Tester Eclipse Regular Expression Tester Features Test and search for regular expression Matches are colorized, for an easy visual clue Support for patte...

weixin_30338743的博客 201

(JAVA)Regular Expression测试

        前一段做毕业设计期间,由于想把程序做的好一点就学习了一下Regular Expression,然后就有了以下代码,做测试。/** RETry.class  * Author: Jack  * Date: 2004-10   */import java.util.regex.*;import java.io.*;public class RETry {    public sta

rebollee的专栏 512

Uncaught SyntaxError: Invalid regular expression flags(看页面源代码)

Uncaught SyntaxError: Invalid regular expression flags(看页面源代码) 一、总结 js或者jquery方面的错误看页面源代码,一下子错误就很清晰了 二、Uncaught SyntaxError: Invalid regular expression flags 页面用jquery中的ajax的时候出现这个错误 1 $(do...

weixin_33910434的博客 2万+

linux中grep的用法以及regular expression的用法

linux中grep的用法以及regular expression的用法

Blog of Tom Chao Zhou 2682

Firefox 扩展插件 Regular Expression Tester

Firefox 扩展插件 Regular Expression Tester

艾特 474

find_regular_expression

CREATE FUNCTION dbo.find_regular_expression (  @source varchar(5000),  @regexp varchar(1000),  @ignorecase bit = 0 )RETURNS bitAS BEGIN  DECLARE @hr integer  DECLARE @objRegExp integer  DECLARE @objMa

yangshenghong的专栏 534

uniapp编译后报错:语法错误: Invalid regular expression flag 可能的原因之一

uniapp编译后报错:语法错误: Invalid regular expression flag 可能的原因之一 在使用uniapp写代码时,若编译后出现这种报错 可注意代码中是否有以下情况 <navigator :url="/pages/.../...?id=.." class="btn">联系对方</navigator> 这时需将其中的冒号去掉,即 <navigator url="/pages/.../...?id=.." class="btn">联系对方&lt

weixin_46022193的博客 4020
上一篇: subvesion说明文档
下一篇: 美国的狗证上写的十句话
fishriver
博客等级 码龄22年 41粉丝 100原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值