ruby regular Expressions

#!/usr/local/bin/ruby -w
def show_regexp(a,re)
  if a =~ re
    "#{$`}<<#{$&}>>#{$‘}"
  else
    "no match"
  end
end

puts show_regexp(‘very interesting‘,/t/)

puts show_regexp(‘Fats Waller‘,/a/)
时间: 2024-10-27 08:42:51

ruby regular Expressions的相关文章

[转]8 Regular Expressions You Should Know

Regular expressions are a language of their own. When you learn a new programming language, they're this little sub-language that makes no sense at first glance. Many times you have to read another tutorial, article, or book just to understand the "s

Using Regular Expressions in Python

1. 反斜杠的困扰(The Backslash) 有时候需要匹配的文本带有'\',如'\python',因为正则表达式有些特殊字符有特殊意义,所以需要前面加上'\'来消除特殊意义,这里匹配的正则表达式是'\\python',这时候如果要编译这个正则表达式需要re.compile('\\\\python'),因为在传递字符串的时候python本身就需要用'\\'来表示'\',也就造成了反斜杠的泛滥. 使用前缀'r'可以解决这个问题:’r'之后的'\'只是这个字符本身而没有特殊意义,比如r'\n'表

PCRE Perl Compatible Regular Expressions Learning

catalog 1. PCRE Introduction 2. pcre2api 3. pcre2jit 4. PCRE Programing 1. PCRE Introduction The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5. PCRE has its own nat

8 Regular Expressions You Should Know

Regular expressions are a language of their own. When you learn a new programming language, they're this little sub-language that makes no sense at first glance. Many times you have to read another tutorial, article, or book just to understand the "s

Finding Comments in Source Code Using Regular Expressions

Many text editors have advanced find (and replace) features. When I’m programming, I like to use an editor with regular expression search and replace. This feature is allows one to find text based on complex patterns rather than based just on literal

Eloquent JavaScript #09# Regular Expressions

索引 Notes js创建正则表达式的两种方式 js正则匹配方式(1) 字符集合 重复匹配 分组(子表达式) js正则匹配方式(2) The Date class 匹配整个字符串 Choice patterns 正则匹配的机制 回溯Backtracking Replace 贪婪匹配Greed 动态构建正则表达式 Search The lastIndex property 遍历匹配项 解析INI文件 国际字符 Excercise Regexp golf Quoting style Numbers

regular expressions

regular expressions 参考博客:https://blog.csdn.net/zhouzhaoxiong1227/article/details/52026323?utm_source=blogxgwz1 1.数字 1)正整数: ^[1-9][0-9]*$ 2)非正整数: ^((-[1-9][0-9]*)|(0))$ 3)负整数:^-[1-9][0-9]*$ 4)整数: ^(0|-?[1-9][0-9]*)$ 5)非负浮点数:^\d+(\.\d+)?$ 2.字母 1)英文字符串:

Python re module (regular expressions)

regular expressions (RE) 简介 re模块是python中处理正在表达式的一个模块 1 r"""Support for regular expressions (RE). 2 3 This module provides regular expression matching operations similar to 4 those found in Perl. It supports both 8-bit and Unicode strings; b

[Regular Expressions] Find Repeated Patterns

Regular Expression Quantifiers allow us to identify a repeating sequence of characters of minimum and maximum lengths. In this lesson we'll use Regular Expression Quantifiers to match repeated patterns, common Quantifier patterns, and using shorthand