Perl正则表达式
Metacharacters
To present a metacharacter as a data character standing for itself,precede it with? Repetition
Read the notation?a’s as “occurrences of strings,each of which matches the pattern?”. Read?repetition?as any of the repetition expressions listed above it. Shortest match means that the shortest string matching the pattern is taken. The default is?“greedy matching”,which finds the longest match. Therepetition Calling these "wildcards" may actually conflict with the theoretical grammar and syntax of Perl,but in fact is the most intuitive way to think of it,and will not lead to any coding mistakes. .???Match?any?character w??Match?"word"?character?(alphanumeric?plus?"_") W??Match?non-word?character s??Match?whitespace?character S??Match?non-whitespace?character d??Match?digit?character D??Match?non-digit?character t??Match?tab n??Match?newline r??Match?return f??Match?formfeed a??Match?alarm?(bell,?beep,?etc) e??Match?escape 21??Match?octal?char?(?in?this?case?21?octal) xf0??Match?hex?char?(?in?this?case?f0?hexidecimal) You can follow any character,wildcard,or series of characters and/or wildcard with a repetiton. Here's where you start getting some power: *??????Match?0?or?more?times +??????Match?1?or?more?times ???????Match?1?or?0?times {n}????Match?exactly?n?times {n,}???Match?at?least?n?times {n,m}??Match?at?least?n?but?not?more?than?m?times Code????????????????Meaning ----------??????????-------------------------------------------- w??????????????????Alphanumeric?Characters W??????????????????Non-Alphanumeric?Characters s??????????????????White?Space S??????????????????Non-White?Space d??????????????????Digits D??????????????????Non-Digits? b??????????????????Word?Boundary B??????????????????Non-Word?Boundary A?or?^?????????????At?the?beginning?of?a?string Z?or?$?????????????At?the?end?of?a?string .???????????????????Match?Any?single?character *???????????????????Zero?or?more?occurrences ????????????????????Zero?or?one?Occurences +???????????????????one?or?more?occurences {N}?????????????????Exactly?N?occurences {N,M}???????????????Between?N?and?M?occurences .*<thingy>??????????Greedy?Match,?up?to?the?last?thingy .*?<thingy>?????????Non-Greedy?match,?up?to?the?first?thingy [set_of_things]?????Match?any?item?in?the?set [^set_of_things]????Does?not?match?anything?in?the?set (some_expression)???Tag?an?expression $1..$N??????????????Tagged?expressions?used?in?substitutions (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |