The method Regexp#match matches a regular expression against a string. : Regexps « Development « 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 » Development » Regexps 
The method Regexp#match matches a regular expression against a string.



If unsuccessful,the method returns nil.
# On success,it returns an instance of class MatchData. 
# And that MatchData object gives you access to all available in formation.

re = /cat/ 
puts re.class # Regexp 


re = /(\d+):(\d+)/ # match a time hh:mm 
md = re.match("Time: 12:34am"
puts md.class 
puts md[0
puts md[1
puts md[2
puts md.pre_match 
puts md.post_match

 
Related examples in the same category
1. Regexps use elements to instruct the regular expression engine on how to find a given string.
2. An example of a regular expression used to match a string with the String method scan.
3. Search for a word from the very beginning
4. Looking for a word
5. grep(/men/)
6. grep(/m[ae]n/)
7. grep(/men|man/)
8. grep(/m(e|a)n/)
9. grep(/^When in/)
10. grep(/outcast state,$/)
11. grep(/\Aen in/)
12. grep(/e n,\z/)
13. grep(/[\(\d\d\d\)]?\d\d\d-\d\d\d\d/)
14. grep(/colou?r/)
15. grep(/[\(\d+\)]?\d+-\d+/)
16. grep(/[\(\d{3}\)]?\d{3}-\d{4}/)
17. Implementing Class and Singleton Methods
18. Match a time
19. Match Perl, zero or more other chars, then Python
20. Match Perl, a space, and Python
21. Match Perl, zero or more spaces, and Python
22. Match Perl, one or more spaces, and Python
23. Match Perl, whitespace characters, then Python
24. Match Ruby, a space, and either Perl or Python
25. Match a regular repression in if statement
26. sub and gsub replace with regular expressions
27. Replace Perl or Python with Ruby
28. MatchData-related $-variables are in $~
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.