Regular Expressions : grep « String « Ruby

Ruby
1. ActiveRecord
2. Array
3. CGI
4. Class
5. Collections
6. Database
7. Date
8. Design Patterns
9. Development
10. File Directory
11. GUI
12. Hash
13. Language Basics
14. Method
15. Network
16. Number
17. Rails
18. Range
19. Reflection
20. Statement
21. String
22. Threads
23. Time
24. Tk
25. Unit Test
26. Windows Platform
27. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Ruby » String » grep 
Regular Expressions


Pattern             Description
/pattern/options    Pattern pattern in slashes, followed by optional options, one or more of: i for case-insensitive; o for substitute once; x for ignore whitespace, allow comments; m for match multiple lines and newlines as normal characters.
%r!pattern!         General delimited string for a regular expression, where ! can be an arbitrary character.
^                   Matches beginning of line.
$                   Matches end of line.
.                   Matches any character.
\1...\9             Matches nth grouped subexpression.
\10                 Matches nth grouped subexpression if already matched; otherwise, refers to octal representation of a character code.
\n, \r, \t, etc.    Matches character in backslash notation.
\w                  Matches word character; same as [0-9A-Za-z_].
\W                  Matches nonword character; same as [^0-9A-Za-z_].
\s                  Matches whitespace character; same as [\t\n\r\f].
\S                  Matches nonwhitespace character; same as [^\t\n\r\f].
\d                  Matches digit; same as [0-9].
\D                  Matches nondigit; same as [^0-9].
\A                  Matches beginning of a string.
\Z                  Matches end of a string, or before newline at the end.
\z                  Matches end of a string.
\b                  Matches word boundary outside [] or backspace (0x08inside [].
\B                  Matches nonword boundary.
\G                  Matches point where last match finished.
[..]                Matches any single character in brackets, such as [ch].
[^..]               Matches any single character not in brackets.
*                   Matches zero or more of previous regular expressions.
*?                  Matches zero or more of previous regular expressions (nongreedy).
+                   Matches one or more of previous regular expressions.
+?                  Matches one or more of previous regular expressions (nongreedy).
{m}                 Matches exactly m number of previous regular expressions.
{m,}                Matches at least m number of previous regular expressions.
{m,n}               Matches at least m but at most n number of previous regular expressions.
{m,n}?              Matches at least m but at most n number of previous regular expressions (nongreedy).
?                   Matches zero or one of previous regular expression.
|                   Alternation, such as color|colour.
( )                 Groups regular expressions or subexpression, such as col(o|ou)r.
(?#..)              Comment.
(?:..)              Groups without back-references (without remembering matched text).
(?=..)              Specifies position with pattern.
(?!..)              Specifies position with pattern negation.
(?>..)              Matches independent pattern without backtracking.
(?imx)              Toggles i, m, or x options on.
(?-imx)             Toggles i, m, or x options off.
(?imx:..)           Toggles i, m, or x options on within parentheses.
(?-imx:..)          Toggles i, m, or x options off within parentheses.
(?ix-ix: )          Turns on (or offi and x options within this noncapturing group.
[:alnum:]           class for alphanumeric.
[:alpha:]           class for uppercase and lowercase letters.
[:blank:]           class for blank and tab.
[:cntrl:]           class for Control characters.
[:digit:]           class for digits.
[:graph:]           class for printable characters (but not space).
[:lower:]           class for lowercase letter.
[:print:]           class for printable characters (space included).
[:punct:]           class for printable characters (but not space and alphanumeric).
[:space:]           class for whitespace.
[:upper:]           class for uppercase letters.
[:xdigit:]          class for hex digits: A-F, a-f, and 0-9.

 
Related examples in the same category
1. match the first line just by using a word in the pattern
2. a pair of square brackets ([]) matches any character in the brackets
3. match alternate forms of a pattern using the pipe character (|)
4. Grouping uses parentheses to group a subexpression, like this one that contains an alternation
5. Anchors anchor a pattern to the beginning (^) or end ($) of a line
6. \d represents a digit; it is the same as using [0-9].
7. Similar to $, the shortcut \z matches the end of a string, not a line
8. Find out the phone number
9. ? is a repetition operator
10. The plus sign (+) operator indicates one or more of the previous pattern
11. Braces ({}) specifies the exact number of digits, such as \d{3} or \d{4}
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.