How to resolve the algorithm Regular expressions step by step in the REXX programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Regular expressions step by step in the REXX programming language

Table of Contents

Problem Statement

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Regular expressions step by step in the REXX programming language

Source code in the rexx programming language

/*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
y="You"    ;  if left($string,length(y))\=y  then say 'It does not start with:'  y
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.*/


/*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.*/


/*REXX program shows  non-destructive sub. (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
$string2 = changestr(old,$string,new)
say 'The original string is:'  $string
say 'The  changed string is:'  $string2
                                       /*stick a fork in it, we're done.*/


/*REXX program shows  test and substitute  (modeled after Perl example).*/
 $string = "I am a string"
     old = " am "
     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)
           say 'I was able to find and replace ' old " with " new
           end
                                       /*stick a fork in it, we're done.*/


  

You may also check:How to resolve the algorithm Left factorials step by step in the Wren programming language
You may also check:How to resolve the algorithm Random numbers step by step in the Lobster programming language
You may also check:How to resolve the algorithm Five weekends step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Playing cards step by step in the Perl programming language
You may also check:How to resolve the algorithm Imaginary base numbers step by step in the Phix programming language