Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
2
Task/Regular-expressions/8th/regular-expressions.8th
Normal file
2
Task/Regular-expressions/8th/regular-expressions.8th
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"haystack" /a./ r:match . cr
|
||||
"haystack" /a./ "blah" s:replace! . cr
|
||||
22
Task/Regular-expressions/Lasso/regular-expressions.lasso
Normal file
22
Task/Regular-expressions/Lasso/regular-expressions.lasso
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
local(mytext = 'My name is: Stone, Rosetta
|
||||
My name is: Hippo, Campus
|
||||
')
|
||||
|
||||
local(regexp = regexp(
|
||||
-find = `(?m)^My name is: (.*?), (.*?)$`,
|
||||
-input = #mytext,
|
||||
-replace = `Hello! I am $2 $1`,
|
||||
-ignorecase
|
||||
))
|
||||
|
||||
|
||||
while(#regexp -> find) => {^
|
||||
#regexp -> groupcount > 1 ? (#regexp -> matchString(2) -> trim&) + '<br />'
|
||||
^}
|
||||
|
||||
#regexp -> reset(-input = #mytext)
|
||||
#regexp -> findall
|
||||
|
||||
#regexp -> reset(-input = #mytext)
|
||||
'<br />'
|
||||
#regexp -> replaceall
|
||||
9
Task/Regular-expressions/Nim/regular-expressions.nim
Normal file
9
Task/Regular-expressions/Nim/regular-expressions.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import re
|
||||
|
||||
var s = "This is a string"
|
||||
|
||||
if s.find(re"string$") > -1:
|
||||
echo "Ends with string."
|
||||
|
||||
s = s.replace(re"\ a\ ", " another ")
|
||||
echo s
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
var str = "I am a string";
|
||||
if (str =~ /string$/) {
|
||||
print "Ends with 'string'\n";
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
var str = <<'EOF';
|
||||
x:Foo
|
||||
y:Bar
|
||||
EOF
|
||||
|
||||
while (var m = str=~/(\w+):(\S+)/g) {
|
||||
say "#{m[0]} -> #{m[1]}";
|
||||
}
|
||||
12
Task/Regular-expressions/Sidef/regular-expressions-3.sidef
Normal file
12
Task/Regular-expressions/Sidef/regular-expressions-3.sidef
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
var str = "I am a string";
|
||||
|
||||
# Substitute something mached by a regex
|
||||
str.sub!(/ a /, ' another '); # "I am a string" => "I am another string"
|
||||
|
||||
# Remove something matched by a regex
|
||||
str -= / \Kanother /i; # "I am another string" => "I am string"
|
||||
|
||||
# Global subtitution with a block
|
||||
str = str.gsub(/(\w+)/, {|s1| 'x' * s1.len}); # globaly replace any word with 'xxx'
|
||||
|
||||
say str; # prints: 'x xx xxxxxx'
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import Foundation
|
||||
|
||||
let str = "I am a string"
|
||||
if let range = str.rangeOfString("string$", options: .RegularExpressionSearch) {
|
||||
println("Ends with 'string'")
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import Foundation
|
||||
|
||||
let orig = "I am the original string"
|
||||
let result = orig.stringByReplacingOccurrencesOfString("original", withString: "modified", options: .RegularExpressionSearch)
|
||||
println(result)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import Foundation
|
||||
|
||||
if let regex = NSRegularExpression(pattern: "string$", options: nil, error: nil) {
|
||||
let str = "I am a string"
|
||||
if let result = regex.firstMatchInString(str, options: nil, range: NSRange(location: 0, length: count(str.utf16))) {
|
||||
println("Ends with 'string'")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
for x in regex.matchesInString(str, options: nil, range: NSRange(location: 0, length: count(str.utf16))) {
|
||||
let match = x as! NSTextCheckingResult
|
||||
// match.range gives the range of the whole match
|
||||
// match.rangeAtIndex(i) gives the range of the i'th capture group (starting from 1)
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import Foundation
|
||||
|
||||
let orig = "I am the original string"
|
||||
if let regex = NSRegularExpression(pattern: "original", options: nil, error: nil) {
|
||||
let result = regex.stringByReplacingMatchesInString(orig, options: nil, range: NSRange(location: 0, length: count(orig.utf16)), withTemplate: "modified")
|
||||
println(result)
|
||||
}
|
||||
1
Task/Regular-expressions/jq/regular-expressions-1.jq
Normal file
1
Task/Regular-expressions/jq/regular-expressions-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"I am a string" | test("string$")
|
||||
1
Task/Regular-expressions/jq/regular-expressions-2.jq
Normal file
1
Task/Regular-expressions/jq/regular-expressions-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"I am a string" | sub(" a "; " another ")
|
||||
1
Task/Regular-expressions/jq/regular-expressions-3.jq
Normal file
1
Task/Regular-expressions/jq/regular-expressions-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"abc" | sub( "(?<head>^.)(?<tail>.*)"; "\(.head)-\(.tail)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue