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
x = "string"
if right($string,length(x))=x then say 'It ends with:' x
 
<br>'''===testing'''===
y = "You"
<lang rexx>/*REXX program demonstrates testing (modeled after Perl example).*/
if left($string,length(y))\=y then say 'It does not start with:' y
$string = "I am a string"
 
say 'The string is:' $string
z = "ring"
x="string" ; if posright(z,$string,length(x))\==0 x then say 'It containsends the stringwith:' zx
y="You" ; if rightleft($string,length(xy))\=xy then say 'It endsdoes not start with:' xy
 
z="ring" ; if pos(z,$string)\==0 then say 'It contains the string:' z
z = "ring"
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>
 
'''===substitution &nbsp; (destructive)'''===
<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>
<pre style="overflow:scroll">
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 &nbsp; (non-destructive)'''
 
'''===substitution &nbsp; (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>
 
'''===test and substitute'''===
<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 &nbsp; '''changestr''' bif&nbsp; BIF, so one is included here: &nbsp; [[CHANGESTR.REX]].
<br><br>