A MatchData object may contain groups or ‘captures’ and these can be returned in an array using either the to_a or captures method, like the following Program
A MatchData object may contain groups or ‘captures’ and these can be returned in an array using either the to_a or captures method, like the following Program
When using match with groups, you can use array-style indexing to obtain specific items. Index 0 is the original string; higher indexes are the groups
The =~ ‘operator’ is not the only means of finding a match. The Regexp class also has a match method.
You can also use a regular expression to match one or more substrings. In order to do this, you should put part of the regular expression between round brackets.
You can control the greediness of pattern matching to do things such as process directory paths
When a string contains more than one potential match, you may sometimes want to return the string up to the first match (that is, as little of the string as possible consistent with the match pattern)
Any code which would normally be executed when a file is run will be executed when that file is required
The file loaded does not introduce the new namespace into the main program and you will not have access to all the module(s) in the loaded file.