Regular expressions: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: removed OVERFLOW from PRE html tags.) |
(solved for maxscript) |
||
Line 937: | Line 937: | ||
I'm a string |
I'm a string |
||
</pre> |
</pre> |
||
=={{header|MAXScript}}== |
|||
<lang MAXScript> |
|||
samples = #("Some string 123","Example text 123","string",\ |
|||
"ThisString Will Not Match","A123,333,string","123451") |
|||
samples2 = #("I am a string","Me too.") |
|||
regex = dotnetobject "System.Text.RegularExpressions.Regex" ".*\bstring*" |
|||
regex2 = dotnetobject "System.Text.RegularExpressions.Regex" "\ba\b" |
|||
clearlistener() |
|||
format "Pattern is : %\n" (regex.toString()) |
|||
for i in samples do |
|||
( |
|||
if regex.ismatch(i) then |
|||
( |
|||
format "The string \"%\" matches the pattern\n" i |
|||
) |
|||
else |
|||
( |
|||
format "The string \"%\" doesn't match the pattern\n" i |
|||
) |
|||
) |
|||
-- replacement |
|||
format "Pattern is : %\n" (regex2.toString()) |
|||
for i in samples2 do |
|||
( |
|||
if regex2.ismatch(i) then |
|||
( |
|||
local replaced = regex2.replace i "another" |
|||
format "The string \"%\" matched the pattern, so it was replaced: \"%\"\n" i replaced |
|||
) |
|||
else |
|||
( |
|||
format "The string \"%\" does not match the pattern\n" i |
|||
) |
|||
) |
|||
</lang> |
|||
Output: |
|||
<lang MAXScript> |
|||
OK |
|||
Pattern is : .*\bstring* |
|||
OK |
|||
The string "Some string 123" matches the pattern |
|||
The string "Example text 123" doesn't match the pattern |
|||
The string "string" matches the pattern |
|||
The string "ThisString Will Not Match" doesn't match the pattern |
|||
The string "A123,333,string" matches the pattern |
|||
The string "123451" doesn't match the pattern |
|||
OK |
|||
Pattern is : \ba\b |
|||
OK |
|||
The string "I am a string" matched the pattern, so it was replaced: "I am another string" |
|||
The string "And me too." does not match the pattern |
|||
OK |
|||
OK |
|||
</lang> |
|||
=={{header|MIRC Scripting Language}}== |
=={{header|MIRC Scripting Language}}== |