首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

ruby 的回顾 正则表达式

2012-08-29 
ruby 的回溯 正则表达式^ - Matches beginning of line$ - Matches end of line\A - Matches beginning of

ruby 的回溯 正则表达式

^ - Matches beginning of line$ - Matches end of line\A - Matches beginning of string.\Z - Matches end of string. If string ends with a newline, it matches just before newline\z - Matches end of string\G - Matches point where last match finished\b - Matches word boundaries when outside brackets; backspace (0x08) when inside brackets\B - Matches non-word boundaries(?=pat) - Positive lookahead assertion: ensures that the following characters match pat, but doesn't include those characters in the matched text(?!pat) - Negative lookahead assertion: ensures that the following characters do not match pat, but doesn't include those characters in the matched text(?<=pat) - Positive lookbehind assertion: ensures that the preceding characters match pat, but doesn't include those characters in the matched text(?<!pat) - Negative lookbehind assertion: ensures that the preceding characters do not match pat, but doesn't include those characters in the matched text# If a pattern isn't anchored it can begin at any point in the string/real/.match("surrealist") #=> #<MatchData "real"># Anchoring the pattern to the beginning of the string forces the# match to start there. 'real' doesn't occur at the beginning of the# string, so now the match fails/\Areal/.match("surrealist") #=> nil# The match below fails because although 'Demand' contains 'and', thepattern does not occur at a word boundary./\band/.match("Demand")# Whereas in the following example 'and' has been anchored to a# non-word boundary so instead of matching the first 'and' it matches# from the fourth letter of 'demand' instead/\Band.+/.match("Supply and demand curve") #=> #<MatchData "and curve"># The pattern below uses positive lookahead and positive lookbehind to# match text appearing in <b></b> tags without including the tags in the# match/(?<=<b>)\w+(?=<\/b>)/.match("Fortune favours the <b>bold</b>")    #=> #<MatchData "bold">

http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm 1 楼 ruby_windy 2012-03-08   在线正则表达式验证:

http://rubular.com/ 2 楼 ruby_windy 2012-03-08  
http://rubular.com/

热点排行