当前位置:网站首页>Learn regular expression options, assertions
Learn regular expression options, assertions
2022-04-23 02:41:00 【An effort to XX program yuan】
Regular expressions for the last few days , Record it here , If you forget later, you can look back .
Explain regular expressions :(?is)(?<=([\W\u4e00-\u9fa5A-Za-z0-9].*\n){6})(.*)(?=:\s*?\r\n\s+?)
Knowledge point 1* (?is) Regular expression options
link : Regular expression option learning
Inline matching pattern , The inline match pattern is usually used instead of enumerating values RegexOptions The specified global match pattern .
Symbol | meaning |
---|---|
(?i) | The expression on the right of the position turns on ignoring case (CASE_INSENSITIVE) |
(?s) | The expression to the right of the position turns on single line mode , Change the period character (.) The meaning of , So that it matches each character ( Not divide \n Match all characters except ) |
(?x) | Ignore space characters (COMMENTS) |
(?m) | The expression on the right of the position turns on the specified multiline mode (MULTILINE), change ^ and $ The meaning of , So that they match the beginning and end of any line respectively , Instead of just matching the beginning and end of the entire string |
(?u) | Yes Unicode Case insensitive characters (UNICODE_CASE), Must enable CASE_INSENSITIVE |
(?d) | Only ’\n’ It is regarded as the suspension of a line (UNIX_LINES) |
Be careful :
- (?s) Usually used when matching text with a newline ;
- (?m) Only regular expressions involving multiple lines “^” and “$” When matching , Only use Multiline Pattern ;
- The above matching patterns can be combined , such as (?is),(?im);
- It can be used (?i:exp) perhaps (?i)exp(?-i) To specify the valid range of the match .
summary :(?is) The meaning of is that the expression on the right ignores case and . Can match each character
Knowledge point 2* (?<=exp)(?=) Zero width assertion 、 Look around
link :1. Assertion ;2.(exp),(?:exp),(?=exp) understand ;3. Zero width assertion details
With (?=exp) For example , This is called " Zero width is asserting ", There are other articles called " Zero - width forward prediction antecedent assertion ", Name doesn't matter , The description is the same .
Symbol | name | meaning |
---|---|---|
reg(?=exp) | Zero width is asserting | reg The content after the matching content meets exp The rules |
reg(?!exp) | Zero width negative antecedent assertion | reg The content after the matching content is not satisfied exp The rules |
(?<=exp)reg | Zero width positive trailing assertion | reg The content in front of the matching content meets exp The rules |
(?<!exp)reg | Zero width negative post assertion | reg The content in front of the matching content is not satisfied exp The rules |
" Go ahead " Indicates that the position to be verified is in the front , That is, the position of verification is exp Before the matching content
" just " Express exp Describe the rules , Match the content after the verification position
summary :
(?<=([\W\u4e00-\u9fa5A-Za-z0-9].\n){6}) Indicates that the matching content is satisfied in front of “([\W\u4e00-\u9fa5A-Za-z0-9].\n){6}” expression ;
(?=:\s*?\r\n\s+?) It means that the matching content meets “:\s*?\r\n\s+?” expression .
Knowledge point 3* () Regular expression groups
link :Java Regular expression groups
- We can combine multiple characters into one unit through parentheses . for example ,(ab)
- Each group in a regular expression has a group number , from 1 Start
- Matcher Methods in class groupCount() Return and Matcher The number of instances in the associated pattern
- Group 0 Reference to the entire regular expression and not by groupCount() Method report
- Each left parenthesis in the regular expression marks the beginning of a new group
- We can return the reference group number in the regular expression .
summary :(.*) Indicates matching multiple arbitrary characters .
Knowledge point 4* Greedy and lazy patterns
link : .? or .+ What does that mean?
greedy : Match strings as long as possible
lazy : Match the shortest possible string
Lazy mode is enabled by simply adding... After repeating metacharacters ? that will do
- *? Repeat any number of times , But repeat as little as possible
- +? repeat 1 Times or more , But repeat as little as possible
- ?? repeat 0 Time or 1 Time , But repeat as little as possible
- {n,m}? repeat n To m Time , But repeat as little as possible
- {n,}? repeat n More than once , But repeat as little as possible
Basic knowledge point reference : regular expression syntax ;java Regular expressions ; Regular expression concise reference
版权声明
本文为[An effort to XX program yuan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230239165857.html
边栏推荐
- Intelligent agricultural management model
- This is how the power circuit is designed
- RT_ Thread ask and answer
- C language 171 Number of recent palindromes
- Rhcsa day 1 operation
- Interpretation of the future development of smart agriculture
- 011_ Redistemplate operation hash
- Global, exclusive and local routing guard
- 工业互联网+危化安全生产综合管理平台怎样建
- [wechat applet] set the bottom menu (tabbar) for the applet
猜你喜欢
Interim summary (Introduction + application layer + transportation layer)
windows MySQL8 zip安装
SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
Hack the box optimum
This is how the power circuit is designed
机器学习(周志华) 第十四章概率图模型
定了,今日起,本号粉丝可免费参与网易数据分析培训营!
[unity3d] rolling barrage effect in live broadcasting room
Target narak
Flink stream processing engine system learning (III)
随机推荐
Push data from onenet cloud platform to database
Servlet template engine usage example
Target narak
win查看端口占用 命令行
JZ76 删除链表中重复的结点
一、序列模型-sequence model
windows MySQL8 zip安装
Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow
The second day of learning rhcsa
This is how the power circuit is designed
Interpretation of the future development of smart agriculture
Leetcode cooking
[untitled]
JVM类加载器
[XJTU計算機網絡安全與管理]第二講 密碼技術
IAR嵌入式開發STM32f103c8t6之點亮LED燈
十六、异常检测
Niuke hand speed monthly race 48 C (I can't understand the difference. It belongs to yes)
想用Mac学习sql,主要给自己个充足理由买Mac听听意见
[xjtu Computer Network Security and Management] session 2 Cryptographic Technology