Anonymous user
Regular expressions: Difference between revisions
m
→{{header|REXX}}: implemented version names, added whitespace and changed indentations.
(solved for maxscript) |
m (→{{header|REXX}}: implemented version names, added whitespace and changed indentations.) |
||
Line 1,610:
=={{header|REXX}}==
Rexx does not directly support the use of regular expressions as part of the language.
<br>However, some rexx interpreters offer support for regular expressions via external function libraries or
Line 1,616 ⟶ 1,615:
<br><br>It is also possible to emulate regular expressions through appropriate coding techniques.
<br><br>All of the following REXX examples are modeled after the '''PERL''' examples.
<br>'''testing'''▼
<lang rexx>/*REXX program demonstrates testing (modeled after Perl example).*/▼
$string = "I am a string"▼
say 'The string is:' $string▼
if right($string,length(x))=x then say 'It ends with:' x▼
▲<lang rexx>/*REXX program demonstrates testing (modeled after Perl example).*/
▲ say 'The string is:' $string
x="string" ; if
z="ring" ; if pos(z,$string)\==0 then say 'It contains the string:' z
z="ring" ; if wordpos(z,$string)==0 then say 'It does not contain the word:' z
/*stick a fork in it, we're done.*/</lang>
{{out}}
Line 1,640 ⟶ 1,633:
It does not contain the word: ring
</pre>
<lang rexx>/*REXX program demonstrates substitution (modeled after Perl example).*/
$string = "I am a string"
old = " a "
new = " another "
say 'The original string is:' $string
say 'old word is:' old
say 'new word is:' new
$string = changestr(old,$string,new)
say 'The changed string is:' $string
/*stick a fork in it, we're done.*/</lang>
{{out}}
<pre>
The original string is: I am a string
old word is: a
Line 1,658 ⟶ 1,652:
The changed string is: I am another string
</pre>
'''substitution (non-destructive)'''▼
<lang rexx>/*REXX program shows non-destructive sub. (modeled after Perl example).*/
$string = "I am a string"
Line 1,664 ⟶ 1,660:
new = " another "
say 'The original string is:' $string
say 'old word is:' old
say 'new word is:' new
$string2 = changestr(old,$string,new)
say 'The original string is:' $string
Line 1,678 ⟶ 1,674:
The changed string is: I am another string
</pre>
<lang rexx>/*REXX program shows test and substitute (modeled after Perl example).*/
$string = "I am a string"
Line 1,684 ⟶ 1,681:
new = " was "
say 'The original string is:' $string
say 'old word is:' old
say 'new word is:' new
if wordpos(old,$string)\==0 then
do
$string = changestr(old,$string,new)
Line 1,700 ⟶ 1,697:
I was able to find and replace am with was
</pre>
Some older REXXes don't have a '''changestr'''
<br><br>
|