This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String title = "Regular Expressions in 10 different languages"; | |
| // Note we have to escape the \ as that is an escape character in Java | |
| boolean result = title.matches("\\d+"); | |
| // To extract the pattern | |
| Pattern pattern = Pattern.compile("(\\d+)"); | |
| Matcher matcher = pattern.match(title); | |
| while (matcher.find()) { | |
| System.out.printf("There are %s languages represented.", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| title = "Regular Expressions in 10 different languages" | |
| result = re.match(r'.*\d+.*', title) | |
| match = re.search(r'(\d+)', title) | |
| # This will return None match is not found | |
| if (match): | |
| print('There are {} languages represented.'.format(match.group(1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| title = "Regular Expressions in 10 different languages" | |
| # Nil if match not found | |
| result = /.*\d+.*/.match(title) | |
| # And extraction too | |
| result = /(\d+)/.match(title) | |
| if result | |
| puts "There are %s languages represented" % result[1] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var title = "Regular Expressions in 10 different languages"; | |
| // This will be true or false | |
| var result = /.*\d+.*/.test(title); | |
| var match = /(\d+)/.exec(title); | |
| if (match) { | |
| console.log("There are ", match[1], " languages represented."); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let title = "Regular Expressions in 10 different languages" | |
| // Match | |
| let pattern = ".*\\d.*" | |
| if let match = title.rangeOfString(pattern, options: .RegularExpressionSearch) { | |
| println("We had a match!") | |
| } | |
| let re = NSRegularExpression(pattern: "(\\d+)", options: nil, error: nil)! | |
| let matches = re.matchesInString( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $title = "Regular Expressions in 10 different languages"; | |
| $pattern = "~(\\d+)~"; | |
| $success = preg_match($pattern, $title, $match); | |
| if ($success) { | |
| echo "There are " . $match[1] . " languages represented."; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string title = "Regular Expressions in 10 different languages"; | |
| string pattern = @"(\d+)"; | |
| foreach (Match match in Regex.Matches(title, pattern)) | |
| Console.WriteLine("There are {0} languages represented.", | |
| match.Groups[1].Value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| title = "Regular Expressions in 10 different languages" | |
| matcher = title =~ /(\d+)/ | |
| matcher.find() | |
| printf("There are %s languages represented", matcher.group(1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val title = "Regular Expressions in 10 different languages" | |
| val pattern = """(\d+)""".r.unanchored | |
| title match { | |
| case pattern(total) => s"There are $total languages represented." | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var shhh = "SECRETPASSWORD"; | |
| function hexToRgb(hex) { | |
| // No RegEx in Espruino yet... | |
| var R, G, B; | |
| if (hex.length == 3) { | |
| R = hex.substring(0, 1); | |
| R = R + R; | |
| G = hex.substring(1, 2); | |
| G = G + G; |
OlderNewer