Ted's Blog

Happy coding

正则表达式备忘

Ted posted @ 2008年9月02日 23:49 in 未分类 , 3872 阅读
正则表达式备忘
字符 描述
\ 将下一个字符标记为一个特殊字符、或一个原义字符、或一个 向后引用、或一个八进制转义符。例如,'n' 匹配字符 "n"。'\n' 匹配一个换行符。序列 '\\' 匹配 "\" 而 "\(" 则匹配 "("。
^ 匹配输入字符串的开始位置。如果设置了 RegExp 对象的 Multiline 属性,^ 也匹配 '\n' 或 '\r' 之后的位置。
$ 匹配输入字符串的结束位置。如果设置了RegExp 对象的 Multiline 属性,$ 也匹配 '\n' 或 '\r' 之前的位置。
* 匹配前面的子表达式零次或多次。例如,zo* 能匹配 "z" 以及 "zoo"。* 等价于{0,}。
+ 匹配前面的子表达式一次或多次。例如,'zo+' 能匹配 "zo" 以及 "zoo",但不能匹配 "z"。+ 等价于 {1,}。
? 匹配前面的子表达式零次或一次。例如,"do(es)?" 可以匹配 "do" 或 "does" 中的"do" 。? 等价于 {0,1}。
{n} n 是一个非负整数。匹配确定的 n 次。例如,'o{2}' 不能匹配 "Bob" 中的 'o',但是能匹配 "food" 中的两个 o。
{n,} n 是一个非负整数。至少匹配n 次。例如,'o{2,}' 不能匹配 "Bob" 中的 'o',但能匹配 "foooood" 中的所有 o。'o{1,}' 等价于 'o+'。'o{0,}' 则等价于 'o*'。
{n,m} m 和 n 均为非负整数,其中n <= m。最少匹配 n 次且最多匹配 m 次。例如,"o{1,3}" 将匹配 "fooooood" 中的前三个 o。'o{0,1}' 等价于 'o?'。请注意在逗号和两个数之间不能有空格。
? 当该字符紧跟在任何一个其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。例如,对于字符串 "oooo",'o+?' 将匹配单个 "o",而 'o+' 将匹配所有 'o'。
. 匹配除 "\n" 之外的任何单个字符。要匹配包括 '\n' 在内的任何字符,请使用象 '[.\n]' 的模式。
(pattern) 匹配 pattern 并获取这一匹配。所获取的匹配可以从产生的 Matches 集合得到,在VBScript 中使用 SubMatches 集合,在JScript 中则使用 $0$9 属性。要匹配圆括号字符,请使用 '\(' 或 '\)'。
(?:pattern) 匹配 pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。这在使用 "或" 字符 (|) 来组合一个模式的各个部分是很有用。例如, 'industr(?:y|ies) 就是一个比 'industry|industries' 更简略的表达式。
(?=pattern) 正向预查,在任何匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如,'Windows (?=95|98|NT|2000)' 能匹配 "Windows 2000" 中的 "Windows" ,但不能匹配 "Windows 3.1" 中的 "Windows"。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始。
(?!pattern) 负向预查,在任何不匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如'Windows (?!95|98|NT|2000)' 能匹配 "Windows 3.1" 中的 "Windows",但不能匹配 "Windows 2000" 中的 "Windows"。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始
x|y 匹配 x 或 y。例如,'z|food' 能匹配 "z" 或 "food"。'(z|f)ood' 则匹配 "zood" 或 "food"。
[xyz] 字符集合。匹配所包含的任意一个字符。例如, '[abc]' 可以匹配 "plain" 中的 'a'。
[^xyz] 负值字符集合。匹配未包含的任意字符。例如, '[^abc]' 可以匹配 "plain" 中的'p'。
[a-z] 字符范围。匹配指定范围内的任意字符。例如,'[a-z]' 可以匹配 'a' 到 'z' 范围内的任意小写字母字符。
[^a-z] 负值字符范围。匹配任何不在指定范围内的任意字符。例如,'[^a-z]' 可以匹配任何不在 'a' 到 'z' 范围内的任意字符。
\b 匹配一个单词边界,也就是指单词和空格间的位置。例如, 'er\b' 可以匹配"never" 中的 'er',但不能匹配 "verb" 中的 'er'。
\B 匹配非单词边界。'er\B' 能匹配 "verb" 中的 'er',但不能匹配 "never" 中的 'er'。
\cx 匹配由 x 指明的控制字符。例如, \cM 匹配一个 Control-M 或回车符。x 的值必须为 A-Z 或 a-z 之一。否则,将 c 视为一个原义的 'c' 字符。
\d 匹配一个数字字符。等价于 [0-9]。
\D 匹配一个非数字字符。等价于 [^0-9]。
\f 匹配一个换页符。等价于 \x0c 和 \cL。
\n 匹配一个换行符。等价于 \x0a 和 \cJ。
\r 匹配一个回车符。等价于 \x0d 和 \cM。
\s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于 [ \f\n\r\t\v]。
\S 匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。
\t 匹配一个制表符。等价于 \x09 和 \cI。
\v 匹配一个垂直制表符。等价于 \x0b 和 \cK。
\w 匹配包括下划线的任何单词字符。等价于'[A-Za-z0-9_]'。
\W 匹配任何非单词字符。等价于 '[^A-Za-z0-9_]'。
\xn 匹配 n,其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。例如,'\x41' 匹配 "A"。'\x041' 则等价于 '\x04' & "1"。正则表达式中可以使用 ASCII 编码。.
\num 匹配 num,其中 num 是一个正整数。对所获取的匹配的引用。例如,'(.)\1' 匹配两个连续的相同字符。
\n 标识一个八进制转义值或一个向后引用。如果 \n 之前至少 n 个获取的子表达式,则 n 为向后引用。否则,如果 n 为八进制数字 (0-7),则 n 为一个八进制转义值。
\nm 标识一个八进制转义值或一个向后引用。如果 \nm 之前至少有 nm 个获得子表达式,则 nm 为向后引用。如果 \nm 之前至少有 n 个获取,则 n 为一个后跟文字 m 的向后引用。如果前面的条件都不满足,若 n 和 m 均为八进制数字 (0-7),则 \nm 将匹配八进制转义值 nm。
\nml 如果 n 为八进制数字 (0-3),且 m 和 l 均为八进制数字 (0-7),则匹配八进制转义值 nml。
\un 匹配 n,其中 n 是一个用四个十六进制数字表示的 Unicode 字符。例如, \u00A9 匹配版权符号 (©)。
 
Avatar_small
liteblue 说:
2020年7月03日 01:09

I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. liteblue

Avatar_small
toll free number 说:
2020年7月05日 04:29

This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! toll free number

Avatar_small
Rainstorm Sounds 说:
2020年7月06日 21:36

I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. Rainstorm Sounds

Avatar_small
Law firm in Nigeria 说:
2020年7月10日 04:40

Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. Law firm in Nigeria

Avatar_small
Robinhood Promo Code 说:
2020年7月21日 00:15

Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. Robinhood Promo Code

Avatar_small
Wallet Minded 说:
2020年9月16日 03:28

Good job! You guys do a great blog, and have some great contents. Keep up the good work.

Avatar_small
ETHENS 说:
2020年9月22日 22:15

There are tons of amazings tools and features for you guys to use. They are exclusively available at the signnow.com/ask/how-to-add-a-signature-in-google-docs. All of them are free, so what are you waiting for? Go and try them out now!

Avatar_small
UMAIR 说:
2021年1月25日 18:20

ISC Sample Papers for Class 12 are available here. Students can view / download ICSE Specimen Paper for their upcoming examination. With the help of ISC ClassISC 10th Class Question Paper 2021 12 Sample Papers, students can get an idea about what kind of questions are asked in the examination. By practicing the sample papers, students can identify their strong and weak areas. For more information regarding ISC Class 12 Sample Papers, students can check below

Avatar_small
UMAIR 说:
2021年1月28日 19:26

I have heard that https://altorotatepdf.com/reviewsreviews offers great types of assistance, However, I am considering perusing the audits and data on https://altoconvertpdftoword.com/blog. You ought to as well.

Avatar_small
UMAIR 说:
2021年2月10日 16:14

I was very impressed by this post, this site has always been pleasant news Thank you very much for such an interesting post, and I meet them more often then I visited this site. https://www.chrisriedy.me/

Avatar_small
budapest short term 说:
2021年2月18日 00:55

I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work

Avatar_small
srwatch 说:
2021年2月21日 07:33

I have shared this article with my friends, and I have asked them to give my feedback. They will share their opinion with me soon, and then I can tell you what they think. You'll appreciate me for doing this.

Avatar_small
what is cbd gummies 说:
2021年2月24日 21:52

I know the best way to edit your documents online. I am talking about the way where you visit , and upload your document. You do nothing else, and the work is done.

Avatar_small
best cbd gummies for 说:
2021年2月27日 18:13

Hello! I just wish to give an enormous thumbs up for the nice info you've got right here on this post. I will probably be coming back to your weblog for more soon!

Avatar_small
cheap abstract paint 说:
2021年3月02日 00:28

I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information.

Avatar_small
สล็อต 说:
2021年3月02日 18:22

I see the greatest contents on your blog and I extremely love reading them.

Avatar_small
Essay writing servic 说:
2021年3月03日 17:45

Your content is nothing short of brilliant in many ways. I think this is engaging and eye-opening material. Thank you so much for caring about your content and your readers.

Avatar_small
Easter baskets for k 说:
2021年3月03日 20:43

Thanks for sharing this information. I really like your blog post very much. You have really shared a informative and interesting blog post with people..

Avatar_small
八尾市英会話 说:
2021年3月05日 01:37

I'm happy to see the considerable subtle element here!.

Avatar_small
office 说:
2021年3月09日 22:08

I read your post and I found it amazing! thank!

Avatar_small
commercial movers ma 说:
2021年6月25日 13:22

Moving is and can be a stressful experience. It can be worse if you choose to do it yourself. This is why it would be best to hire the best movers Manhattan. It is even harder when you consider that there are many moving companies around. But you don’t have to worry.

Avatar_small
Car Removal Melbourn 说:
2021年6月29日 13:09

Rapid Cash for Cars to get up to $9999 cash for cars eastern suburbs Melbourne. Call us (03) 9793 7475 and send ar details to get an instant quote. Call us and get your car wrecking quote right this very minute. Melbourne , Victoria email us at info@rapidcashforcars.com.au or fill out our online contact form.

Avatar_small
Car Removal Geelong 说:
2021年6月29日 13:53

Orion Car Removal Geelong is a locally run car wrecker and removal service company offering you instant cash for used cars. We on spot up to $10,999 for all makes and models of cars, vans, 4WDs and light commercial vehicles in any condition – broken, old, unwanted, damaged and scrap that are no longer roadworthy. We reach your given address to start car removal and hauling service. We dismantle, remove and offer free haulage for any model of Nissan, Mazda, Ford, Toyota, Volvo, Audi, Mitsubishi, Honda, Subaru, BMW, Mercedes and different other brands.

Avatar_small
taxi flughafen hambu 说:
2021年6月29日 15:15

Fast taxi makes it easy to pay online, pay how you like it best. Pay with GiroPay, Apple pay, PayPal, credit card or cash in a taxi. You can also pay in the taxi with your card. You will always receive an invoice / confirmation of your payment in your post office, you can always request a receipt yourself after the ride in the taxi. You can also pay later by invoice. Please note that payment after payment is only possible for business customers or customers who have an account with Schnelleintaxi.

Avatar_small
facebook insights go 说:
2021年6月29日 15:32

There are 50+ Metrics and Dimensions exposed by this connector. Once user successfully logs into the connector he can then choose the metrics and dimensions he is interested to create a report on.

Avatar_small
emerald bình dương 说:
2021年7月03日 06:12

I am impressed with the work shared here by the writer. I think this is one of the best articles you'll read today. If you know of an article which is better, let me know. I can guarantee you won't find a better article.

Avatar_small
florence residences 说:
2021年8月14日 17:04

In the event that you have more information to share regarding this matter, kindly do as such. You've dazzled me fundamentally here today, and I intend to impart your work to a greater amount of my companions. They'll adore it!

Avatar_small
kopar at newton pric 说:
2021年8月16日 15:37

Indeed, I am dazzled with your composing work here, and it would be a joy to see more substance like this. I realize that it's difficult for you to share content reliably, yet I trust you can prevail with some inspiration.

Avatar_small
perfect ten condo sh 说:
2021年8月18日 00:31

You are perhaps the best essayist of this age, and the vast majority will concur with me. Your composing quality is eminent, and if you keep progressing forward this way, you'll become the best ever.

Avatar_small
best web design comp 说:
2021年10月11日 07:11

Your work here is fantastic! The content shared about this subject is perfect, and I will utilize this content in one of my papers. I need to submit this paper soon, and I have all the useful content now. Cheers!

Avatar_small
Best Social Plan 说:
2021年10月14日 01:02

I like what everyone has shared here, and I appreciate the information. I can use this in my paper on this subject, but it will be difficult since there isn't enough social information here. I will get it done, though!

Avatar_small
Buy Top Quality ASUS 说:
2021年11月01日 21:05

I would like to thank you for sharing a brilliant article here. You've done an incredible job with the writing, and I am extremely impressed with your work. I hope to see more content like this soon. I hope I won't be disappointed.

Avatar_small
dark web/deep web/d 说:
2022年8月04日 18:47

This section of the Internet is home to many of the illicit activities and websites that are available on the world wide web today. If you want to know more about how to find out what the Dark Web is and how to stay safe while surfing the web, then read on.  dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:31

Once these criminals get your information, they may use it for illegal activities. Hackers can open up a new account using your name or create entirely new email accounts that contain sensitive information, making it extremely difficult to stop their activities.  deep web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:47

By exposing yourself to the dangers of the dark web links through unsavory websites, you will increase the likelihood that you will become the next victim of computer hackers. dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:10

By staying informed, you will be able to understand the many ways that hackers are trying to infiltrate your computer, and you can prevent them from doing their damage to your identity and your finances. By reading up on the dark web, you will be able to use the information that you find to your advantage.  dark web sites

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:25

If you are visiting a legitimate website, you will not run into any problems with running into dangerous individuals. But, on the dark web, you can't really know what you are looking at.   dark web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:40

Most affiliate marketers start by creating a product to market. In this step, they should already have an idea of the product that they want to sell. The product must be one that a vast majority of people will buy, and it should be something that is easy for them to advertise.   work from home jobs

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:56

The world of affiliate marketing is huge, full of new affiliates, and a whole new marketing landscape that's constantly evolving. This has resulted in affiliate marketing success stories coming out left and right this year.   affiliate marketing success

Avatar_small
Isabel Floyd 说:
2022年10月07日 05:12

Cool article! The information shared here is brilliant, and it will come in handy for me. I am working on a project related to this topic, and I can utilize this information in my project. Thanks for sharing this! where to buy vyvanse


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter