Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,43 +0,0 @@
|
|||
with Ada.Text_IO; with Gnat.Regpat; use Ada.Text_IO;
|
||||
|
||||
procedure Regex is
|
||||
|
||||
package Pat renames Gnat.Regpat;
|
||||
|
||||
procedure Search_For_Pattern(Compiled_Expression: Pat.Pattern_Matcher;
|
||||
Search_In: String;
|
||||
First, Last: out Positive;
|
||||
Found: out Boolean) is
|
||||
Result: Pat.Match_Array (0 .. 1);
|
||||
begin
|
||||
Pat.Match(Compiled_Expression, Search_In, Result);
|
||||
Found := not Pat."="(Result(1), Pat.No_Match);
|
||||
if Found then
|
||||
First := Result(1).First;
|
||||
Last := Result(1).Last;
|
||||
end if;
|
||||
end Search_For_Pattern;
|
||||
|
||||
Word_Pattern: constant String := "([a-zA-Z]+)";
|
||||
|
||||
Str: String:= "I love PATTERN matching!";
|
||||
Current_First: Positive := Str'First;
|
||||
First, Last: Positive;
|
||||
Found: Boolean;
|
||||
|
||||
begin
|
||||
-- first, find all the words in Str
|
||||
loop
|
||||
Search_For_Pattern(Pat.Compile(Word_Pattern),
|
||||
Str(Current_First .. Str'Last),
|
||||
First, Last, Found);
|
||||
exit when not Found;
|
||||
Put_Line("<" & Str(First .. Last) & ">");
|
||||
Current_First := Last+1;
|
||||
end loop;
|
||||
|
||||
-- second, replace "PATTERN" in Str by "pattern"
|
||||
Search_For_Pattern(Pat.Compile("(PATTERN)"), Str, First, Last, Found);
|
||||
Str := Str(Str'First .. First-1) & "pattern" & Str(Last+1 .. Str'Last);
|
||||
Put_Line(Str);
|
||||
end Regex;
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
(let ((string "I am a string"))
|
||||
(when (string-match-p "string$" string)
|
||||
(message "Ends with 'string'"))
|
||||
(message "%s" (replace-regexp-in-string " a " " another " string)))
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
"I am a string" -match '\bstr' # true
|
||||
"I am a string" -replace 'a\b','no' # I am no string
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
REBOL [
|
||||
Title: "Regular Expression Matching"
|
||||
URL: http://rosettacode.org/wiki/Regular_expression_matching
|
||||
]
|
||||
|
||||
string: "This is a string."
|
||||
|
||||
; REBOL doesn't use a conventional Perl-compatible regular expression
|
||||
; syntax. Instead, it uses a variant Parsing Expression Grammar with
|
||||
; the 'parse' function. It's also not limited to just strings. You can
|
||||
; define complex grammars that actually parse and execute program
|
||||
; files.
|
||||
|
||||
; Here, I provide a rule to 'parse' that specifies searching through
|
||||
; the string until "string." is found, then the end of the string. If
|
||||
; the subject string satisfies the rule, the expression will be true.
|
||||
|
||||
if parse string [thru "string." end] [
|
||||
print "Subject ends with 'string.'"]
|
||||
|
||||
; For replacement, I take advantage of the ability to call arbitrary
|
||||
; code when a pattern is matched -- everything in the parens will be
|
||||
; executed when 'to " a "' is satisfied. This marks the current string
|
||||
; location, then removes the offending word and inserts the replacement.
|
||||
|
||||
parse string [
|
||||
to " a " ; Jump to target.
|
||||
mark: (
|
||||
remove/part mark 3 ; Remove target.
|
||||
mark: insert mark " another " ; Insert replacement.
|
||||
)
|
||||
:mark ; Pick up where I left off.
|
||||
]
|
||||
print [crlf "Parse replacement:" string]
|
||||
|
||||
; For what it's worth, the above operation is more conveniently done
|
||||
; with the 'replace' function:
|
||||
|
||||
replace string " another " " a " ; Change string back.
|
||||
print [crlf "Replacement:" string]
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
text = "I need more coffee!!!"
|
||||
Set regex = New RegExp
|
||||
regex.Global = True
|
||||
regex.Pattern = "\s"
|
||||
If regex.Test(text) Then
|
||||
WScript.StdOut.Write regex.Replace(text,vbCrLf)
|
||||
Else
|
||||
WScript.StdOut.Write "No matching pattern"
|
||||
End If
|
||||
Loading…
Add table
Add a link
Reference in a new issue