ruby 正则表达式 ruby-doc原文】的更多相关文章

Ruby 正则表达式 正则表达式是一种特殊序列的字符,它通过使用有专门语法的模式来匹配或查找其他字符串或字符串集合. 语法 正则表达式从字面上看是一种介于斜杠之间或介于跟在 %r 后的任意分隔符之间的模式,如下所示: /pattern/ /pattern/im # 可以指定选项 %r!/usr/local! # 一般的分隔的正则表达式 实例 #!/usr/bin/ruby line1 = "Cats are smarter than dogs"; line2 = "Dogs…
ruby正则表达式在线编辑器:rubular 一般规则: /a/匹配字符a.      /\?/匹配特殊字符?.特殊字符包括^, $, ? , ., /, \, [, ], {, }, (, ), +, *.      .匹配任意字符,例如/a./匹配ab和ac  /[ab]c/匹配ac和bc,[]之间代表范围.例如:/[a-z]/ , /[a-zA-Z0-9]/  /[^a-zA-Z0-9]/匹配不在该范围内的字符串  /[\d]/代表任意数字  /[\w]/代表任意字母,数字或者_  /[\…
Ruby学习笔记-正则表达式 Posted on 2011-11-29 17:55 Glen He 阅读(4998) 评论(0) 编辑 收藏 1.创建正则表达式 a) reg1 = /^[a-z]*$/ #将模式的定义放在两个正斜杠之间,返回一个Regexp对象 b) reg2 = Regexp.new(‘^[a-z]*$’) #创建一个Regexp对象 c) reg3 = %r{^[a-z]*$} #使用前置的%r 2.匹配正则式: String和Regexp都支持以下两个方法 a) matc…
Install Ruby(安装) For windows you can download Ruby from http://rubyforge.org/frs/?group_id=167 for Linux tryhttp://www.rpmfind.net. Our first program(从此开始) Enter the following into the file, "test.rb". puts "Howdy!" At the C: prompt en…
原文链接:http://www.ruby-doc.org/core-1.9.3/Regexp.html Regexp A Regexp holds a regular expression, used to match a pattern against strings. Regexps are created using the /.../ and %r{...} literals, and by the Regexp::new constructor. Regular expressions…
1.puts /[一-龥]+/.match("this is 中文")                 =>中文 2.str2="123中文"puts /\p{Han}+/u.match(str2) 文本编码格式:utf-8 文件第一行:#encoding:utf-8 require "rubygems"require "iconv"print Iconv.iconv("GBK","UTF-…
假设一个字符串当中有很多符合规则的信息,下面的例子可以把所有匹配到的结果打印出来: message="afhadhffkdf414j9tr3j43i3433094jwoert223jwew123dfdf" regex=/[a-z](\d{3})[a-z]/ message.scan(regex).each{|m|puts"Test#{m[0]}"} message="afhadhffkdf414j9tr3j43i3433094jwoert223jwew12…
Windows Ruby 安装步骤 准备工作: 1.http://rubyinstaller.org/downloads/ 下载选择Ruby 1.9.3 2.http://rubyinstaller.org/downloads/ 下载DEVELOPMENT KIT 注意版本和1对应 3.http://www.sqlite.org/download.html 选择Precompiled Binaries for Windows然后下载前两个:sqlite-shell-win32-x86-30715…
sudo apt-get install ruby #find an folder and: git clone https://github.com/rubygems/rubygems.git cd rubygem ruby setup.rb…