September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -8,4 +8,4 @@ ENDIF.
|
|||
REPLACE ALL OCCURRENCES OF REGEX '[t|T]est' IN text WITH 'Regex'.
|
||||
|
||||
cl_demo_output=>write( text ).
|
||||
cl_demo_output=>display(
|
||||
cl_demo_output=>display( ).
|
||||
|
|
|
|||
11
Task/Regular-expressions/Gambas/regular-expressions.gambas
Normal file
11
Task/Regular-expressions/Gambas/regular-expressions.gambas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Public Sub Main()
|
||||
Dim sString As String = "Hello world!"
|
||||
|
||||
If sString Ends "!" Then Print sString & " ends with !"
|
||||
If sString Begins "Hel" Then Print sString & " begins with 'Hel'"
|
||||
|
||||
sString = Replace(sString, "world", "moon")
|
||||
|
||||
Print sString
|
||||
|
||||
End
|
||||
11
Task/Regular-expressions/Kotlin/regular-expressions.kotlin
Normal file
11
Task/Regular-expressions/Kotlin/regular-expressions.kotlin
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// version 1.0.6
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s1 = "I am the original string"
|
||||
val r1 = Regex("^.*string$")
|
||||
if (s1.matches(r1)) println("`$s1` matches `$r1`")
|
||||
val r2 = Regex("original")
|
||||
val s3 = "replacement"
|
||||
val s2 = s1.replace(r2, s3)
|
||||
if (s2 != s1) println("`$s2` replaces `$r2` with `$s3`")
|
||||
}
|
||||
42
Task/Regular-expressions/OoRexx/regular-expressions.rexx
Normal file
42
Task/Regular-expressions/OoRexx/regular-expressions.rexx
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* Rexx */
|
||||
/* Using the RxRegExp Regular Expression built-in utility class */
|
||||
|
||||
st1 = 'Fee, fie, foe, fum, I smell the blood of an Englishman'
|
||||
rx1 = '[Ff]?e' -- unlike most regex engines, RxRegExp uses '?' instead of '.' to match any single character
|
||||
sbx = 'foo'
|
||||
|
||||
myRE = .RegularExpression~new()
|
||||
myRE~parse(rx1, MINIMAL)
|
||||
|
||||
mcm = myRE~pos(st1)
|
||||
say 'String "'st1'"' 'matches pattern "'rx1'":' bool2string(mcm > 0)
|
||||
say
|
||||
|
||||
-- The RxRegExp package doesn't provide a replace capability so you must roll your own
|
||||
st0 = st1
|
||||
loop label GREP forever
|
||||
mcp = myRE~pos(st1)
|
||||
if mcp > 0 then do
|
||||
mpp = myRE~position
|
||||
fnd = st1~substr(mcp, mpp - mcp + 1)
|
||||
stx = st1~changestr(fnd, sbx, 1)
|
||||
end
|
||||
else leave GREP
|
||||
st1 = stx
|
||||
end GREP
|
||||
say 'Input string: "'st0'"'
|
||||
say 'Result string: "'stx'"'
|
||||
return
|
||||
exit
|
||||
|
||||
bool2string:
|
||||
procedure
|
||||
do
|
||||
parse arg bv .
|
||||
if bv then bx = 'true'
|
||||
else bx = 'false'
|
||||
return bx
|
||||
end
|
||||
exit
|
||||
|
||||
::requires "rxregexp.cls"
|
||||
10
Task/Regular-expressions/Phix/regular-expressions.phix
Normal file
10
Task/Regular-expressions/Phix/regular-expressions.phix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
include builtins\regex.e
|
||||
string s = "I am a string"
|
||||
printf(1,"\"%s\" %s with string\n",{s,iff(length(regex(`string$`,s))?"ends":"does not end")})
|
||||
printf(1,"\"%s\" %s with You\n",{s,iff(length(regex(`^You`,s))?"starts":"does not start")})
|
||||
?gsub(`[A-Z]`,"abCDefG","*")
|
||||
?gsub(`[A-Z]`,"abCDefGH","(&)")
|
||||
?gsub(`[A-Z]+`,"abCDefGH","(&)")
|
||||
?gsub(`string`,s,"replacement")
|
||||
s = gsub(`\ba\b`,s,"another") ?s
|
||||
?gsub(`string`,s,"replacement")
|
||||
7
Task/Regular-expressions/Stata/regular-expressions.stata
Normal file
7
Task/Regular-expressions/Stata/regular-expressions.stata
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
scalar s="ars longa vita brevis"
|
||||
|
||||
* is there a vowel?
|
||||
di regexm(s,"[aeiou]")
|
||||
|
||||
* replace the first vowel with "?"
|
||||
di regexr(s,"[aeiou]","?")
|
||||
11
Task/Regular-expressions/Zkl/regular-expressions-1.zkl
Normal file
11
Task/Regular-expressions/Zkl/regular-expressions-1.zkl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
var re=RegExp(".*string$");
|
||||
re.matches("I am a string") //-->True
|
||||
var s="I am a string thing"
|
||||
re=RegExp("(string)") // () means group, ie if you see it, save it
|
||||
re.search(s,True) //-->True, .search(x,True) means search for a match, ie don't need .*
|
||||
p,n:=re.matched[0] //.matched-->L(L(7,6),"string")
|
||||
String(s[0,p],"FOO",s[p+n,*]) //-->"I am a FOO thing"
|
||||
|
||||
re.search(s,True); // using .matched clears it
|
||||
m:=re.matched[1];
|
||||
s.replace(m,"FOO"); // -->"I am a FOO thing"
|
||||
5
Task/Regular-expressions/Zkl/regular-expressions-2.zkl
Normal file
5
Task/Regular-expressions/Zkl/regular-expressions-2.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var s=Data(0,Int,"I am a string thing");
|
||||
re.search(s,True);
|
||||
p,n:=re.matched[0];
|
||||
s[p,n]="FOO";
|
||||
s.text //-->"I am a FOO thing"
|
||||
Loading…
Add table
Add a link
Reference in a new issue