正则表达式

535 阅读3分钟

操作符

^1[3-9](\d{9})$
^: 匹配字符串的开头,如果^在列表操作符中使用,并且在首位,代表取反。
[]: 只匹配中括号中的一个字符
(): 分组/捕获组 定义一个子表达式
\d: 代表0-9数字
{}: 匹配前一个元素几次
$: 匹配字符串的结尾
.: 匹配所有的字符,除了newline和null
*: 匹配前一个元素0次或多次 
+: 匹配前一个元素1次或多次 
?: 匹配前一个元素0次或1次
{count}: 匹配前一个元素count次
{min,}: 匹配前一个元素至少min次
{min, max}: 匹配前一个元素至少min次,至多max次
|: 匹配前一个表达式或后一个表达式
[A-Za-z0-9]: 数字和字母字符
A-Za-z] : 字母字符
[\t]:  空格和TAB
][!"#$%&'()*+,./:;<=>?@\^_`{|}~-]: 标点符号
[\t\r\n\v\f]: 空白字符
[A-Fa-f0-9]: 十六进制字符
\w:  数字和字母字符
\d:  数字
\W:  除了数字和字母字符
\B:  除了数字
\<:  匹配字符串的开头
\>:  匹配字符串的结尾

grep

grep -E "description(.*)[\"]$"
-v:逆转显示
-i:忽略大小写
-A:向上显示几行 -B:向下显示几行
-E:启用扩展
—color:显示颜色 
egrep:grep -E

示例


$grep "TG" 变量的定义.swift

$grep "TG" 变量的定义.swift -A 1

$grep "TG" 变量的定义.swift -A 1 -B 1

$grep "tgteacher" 变量的定义.swift -i

$grep "TGTeacher" 变量的定义.swift -v

$grep "TGTeacher[^s]" 变量的定义.swift

$grep "oo" 变量的定义.swift

$grep "[^a-z]oo" 变量的定义.swift

$grep "[^[:lower:]]oo" 变量的定义.swift

$grep "[^A-Za-z]oo" 变量的定义.swift

$grep "[0-9]oo" 变量的定义.swift

$grep "[^A-Za-z0-9]oo" 变量的定义.swift

$grep "\woo" 变量的定义.swift


struct TGTeacher {
    let name: String
    let class: String
    let credit:String
    let description: String
}

struct TGTeachers {
    let name: String
    let class: String
    let credit:String
    let description: String
}

extension TGTeacher {
    static var all: [TGTeacher] {
        [ TGTeacher(
            name: "Cooci",
            license: "http://creativecommons.org/licenses/by-sa/3.0",
            credit: "http://commons.wikimedia.org/wiki/User:Lin%C3%A91",
            description: "Basil is commonly used fresh in cooked recipes. In general, it is added at the last moment, as cooking quickly destroys the flavor. The fresh herb can be kept for a short time in plastic bags in the refrigerator, or for a longer period in the freezer, after being blanched quickly in boiling water. The dried herb also loses most of its flavor, and what little flavor remains tastes very different.9oo *oo"
        ),
        TGTeacher(
            name: "Kody",
            license: "http://creativecommons.org/licenses/by-sa/3.0",
            credit: "http://commons.wikimedia.org/wiki/User:Lin%C3%A91",
            description: "Saffron's aroma is often described by connoisseurs as reminiscent of metallic honey with grassy or hay-like notes, while its taste has also been noted as hay-like and sweet. Saffron also contributes a luminous yellow-orange colouring to foods. Saffron is widely used in Indian, Persian, European, Arab, and Turkish cuisines. Confectioneries and liquors also often include saffron."
        ),
        TGTeacher(
            name: "Hank",
            license: "http://creativecommons.org/licenses/by-sa/3.0",
            credit: "http://commons.wikimedia.org/wiki/User:Raul654",
            description: "Marjoram is used for seasoning soups, stews, dressings and sauce. Majorana has been scientifically proved to be beneficial in the treatment of gastric ulcer, hyperlipidemia and diabetes. Majorana hortensis herb has been used in the traditional Austrian medicine for treatment of disorders of the gastrointestinal tract and infections."
        ),
        TGTeacher(
            name: "CC",
            license: "http://www.gnu.org/licenses/old-licenses/fdl-1.2.html",
            credit: "http://commons.wikimedia.org/wiki/User:Fir0002",
            description: "The leaves, both fresh and dried, are used in traditional Italian cuisine. They have a bitter, astringent taste and are highly aromatic, which complements a wide variety of foods. Herbal tea can be made from the leaves. When burnt, they give off a mustard-like smell and a smell similar to burning wood, which can be used to flavor foods while barbecuing. Rosemary is high in iron, calcium and vitamin B6.")
        ,
        TGTeacher(
            name: "Cat",
            license: "http://commons.wikimedia.org/wiki/File:AniseSeeds.jpg",
            credit: "http://commons.wikimedia.org/wiki/User:Ben_pcc",
            description: "Anise is sweet and very aromatic, distinguished by its characteristic flavor. The seeds, whole or ground, are used in a wide variety of regional and ethnic confectioneries, including black jelly beans, British aniseed balls, Australian humbugs, and others. The Ancient Romans often served spiced cakes with aniseseed, called mustaceoe at the end of feasts as a digestive. "
        )
        ]
    }
}

lldb

# 对指定库中的符合指定的正则表达式的函数下断点
(lldb) breakpoint set —func-regex=.—shlib=libfoo.dylib
简写:
1、br set -r (.*)[bB]lock(.*)[Cc]opy(.*)
2、rb (.*)[bB]lock(.*)[Cc]opy(.*)

# 对符合指定的正则表达式的符号下断点
(lldb) breakpoint set --func-regex regular-expression
简写:
1、rb (.*)[bB]lock(.*)[Cc]opy(.*) --shlib=libsymtem_blocks.dylib
2、rb (.*)[bB]lock(.*)[Cc]opy(.*) -s libsystem_blocks.dylib

# 通过对指定的正则表达式对文件内容设置断点
(lldb) breakpoint set --source-pattern-regexp regular-expression --fil
br set -p (.*)[bB]lock(.*)[Cc]opy(.*) -f runtime.cpp

#自定义命令
command alias pb breakpoint set -p %1 -f %2
pb (.*)[bB]lock(.*)[Cc]opy(.*) runtime.cpp

项目中正则使用

//验证电话号码


注释:字符数不够100不能发表,代码不是字符吗? 2333333333333333333333333333333333333333333333333333333333333333333333333333333333