-
正则表达式类
正则表达式类
正则表达式类用于表示一个正则表达式。
正则表达式类有以下常用方法:
SN | 方法和说明 |
---|---|
1 |
Public Function IsMatch (input As String) As Boolean 表示在正则表达式构造函数中指定的正则表达式是否发现在指定的输入字符串匹配。 |
2 |
Public Function IsMatch (input As String, startat As Integer ) As Boolean 公共函数IsMatch(输入作为字符串,startat作为整数)作为布尔 指示在Regex构造函数中指定的正则表达式是否在指定的输入字符串中找到匹配项,从字符串中指定的起始位置开始。 |
3 |
Public Shared Function IsMatch (input As String, pattern As String ) As Boolean 公共共享函数IsMatch(输入作为字符串,图案作为字符串)作为布尔 指示指定的正则表达式是否在指定的输入字符串中找到匹配项。 |
4 |
Public Function Matches (input As String) As MatchCollection 公共函数匹配(输入作为字符串)作为MatchCollection 搜索指定的输入字符串以查找正则表达式的所有出现。 |
5 |
Public Function Replace (input As String, replacement As String) As String 公共函数替换(输入作为字符串,更换作为字符串)作为字符串 在指定的输入字符串中,使用指定的替换字符串替换与正则表达式模式匹配的所有字符串。 |
6 |
Public Function Split (input As String) As String() 公共函数(输入作为字符串)作为字符串() 将输入字符串插入到由正则表达式构造函数中指定一个正则表达式模式定义的位置的子字符串数组。 |
有关方法和属性的完整列表,请参阅Microsoft文档。
示例1
以下示例匹配以“S”开头的单词:
-
Imports System.Text.RegularExpressions
-
Module regexProg
-
Sub showMatch(ByVal text As String, ByVal expr As String)
-
Console.WriteLine("The Expression: " + expr)
-
Dim mc As MatchCollection = Regex.Matches(text, expr)
-
Dim m As Match
-
For Each m In mc
-
Console.WriteLine(m)
-
Next m
-
End Sub
-
Sub Main()
-
Dim str As String = "A Thousand Splendid Suns"
-
Console.WriteLine("Matching words that start with 'S': ")
-
showMatch(str, "SS*")
-
Console.ReadKey()
-
End Sub
-
End Module
当上述代码被编译和执行时,它产生了以下结果:
-
Matching words that start with 'S':
-
The Expression: SS*
-
Splendid
-
Suns
例2
以下示例匹配以“m”开头并以“e”结尾的单词:
-
Imports System.Text.RegularExpressions
-
Module regexProg
-
Sub showMatch(ByVal text As String, ByVal expr As String)
-
Console.WriteLine("The Expression: " + expr)
-
Dim mc As MatchCollection = Regex.Matches(text, expr)
-
Dim m As Match
-
For Each m In mc
-
Console.WriteLine(m)
-
Next m
-
End Sub
-
Sub Main()
-
Dim str As String = "make a maze and manage to measure it"
-
Console.WriteLine("Matching words that start with 'm' and ends with 'e': ")
-
showMatch(str, "mS*e")
-
Console.ReadKey()
-
End Sub
-
End Module
当上述代码被编译和执行时,它产生了以下结果:
-
Matching words start with 'm' and ends with 'e':
-
The Expression: mS*e
-
make
-
maze
-
manage
-
measure
例3
此示例替换了额外的空白空间:
-
Imports System.Text.RegularExpressions
-
Module regexProg
-
Sub Main()
-
栏目列表最新更新
- nodejs爬虫
- Python正则表达式完全指南
- 爬取豆瓣Top250图书数据
- shp 地图文件批量添加字段
- 爬虫小试牛刀(爬取学校通知公告)
- 【python基础】函数-初识函数
- 【python基础】函数-返回值
- HTTP请求:requests模块基础使用必知必会
- Python初学者友好丨详解参数传递类型
- 如何有效管理爬虫流量?
- SQL SERVER中递归
- 2个场景实例讲解GaussDB(DWS)基表统计信息估
- 常用的 SQL Server 关键字及其含义
- 动手分析SQL Server中的事务中使用的锁
- openGauss内核分析:SQL by pass & 经典执行
- 一招教你如何高效批量导入与更新数据
- 天天写SQL,这些神奇的特性你知道吗?
- openGauss内核分析:执行计划生成
- [IM002]Navicat ODBC驱动器管理器 未发现数据
- 初入Sql Server 之 存储过程的简单使用
- 这是目前我见过最好的跨域解决方案!
- 减少回流与重绘
- 减少回流与重绘
- 如何使用KrpanoToolJS在浏览器切图
- performance.now() 与 Date.now() 对比
- 一款纯 JS 实现的轻量化图片编辑器
- 关于开发 VS Code 插件遇到的 workbench.scm.
- 前端设计模式——观察者模式
- 前端设计模式——中介者模式
- 创建型-原型模式