.net - 有人可以帮我理解这个正则表达式在做什么吗?
问题描述
有人可以分解这个正则表达式匹配的内容吗?
Regex.Match("<a>", "^<([a-zA-Z][a-zA-Z0-9]*)( [^>]*)?>$")
解决方案
给你,解释和格式化
^ # The beginning of the string BOS
< # A literal '<'
( # (1 start), Capture group 1
[a-zA-Z] # Start with a letter
[a-zA-Z0-9]* # 0 or more letter or number
) # (1 end)
( # (2 start) Optional Capture group 2
[^>]* # 0 or more, non '>' character
)? # (2 end)
> # A literal '>'
$ # The end of the string EOS
一个忠告,这个结构有它的位置([^>]*)?
,但它应该写成 this ([^>]*?)
。
推荐阅读
- json - 无法读取角度 6 中未定义的属性“0”
- java - Spring Data Rest 嵌套属性排序与 JsonUnwrapped
- amazon-rds - 将 Java-Spring 应用程序战争连接到 AWS RDS Oracle 数据库实例
- r - 使用 R-markdown knitr hooks 自定义 HTML 报告中的表格格式
- python - 如何使要打印的参数分开而不是空格分隔
- sbt - 如何根据 sbt 中的 crossScalaVersions 更改 unmanagedBase
- java - 如何在 Spring Webflux 控制器中结合 Flux 和 ResponseEntity
- windows - WSUS 中的“导入更新”选项已禁用
- java - 如果用户已从存储目录中删除项目表单recyclerview,如何删除它?
- python - 如何在python中将列表元素作为键添加到字典中