Jump to content

StringRegExpReplace. Problem with cutting out founded


Suppir
 Share

Recommended Posts

Hello!

I have the code:

for $i = 0 to UBound($Search) - 1

$Text = StringRegExpReplace($Text, $Search[$i][0], $Search[$i][1])

Next

$Search[$i][0] - is a regular exression to search

$Search[$i][0] - is a text to replace founded

How to cut out the founded if my $Search[$i][1] defined but equals "nothing"? (not assigned any value)

In this situation replace does not work.

Edited by Suppir
Link to comment
Share on other sites

Hello!

I have the code:

for $i = 0 to UBound($Search) - 1

$Text = StringRegExpReplace($Text, $Search[$i][0], $Search[$i][1])

Next

$Search[$i][0] - is a regular exression to search

$Search[$i][0] - is a text to replace founded

How to cut out the founded if my $Search[$i][1] defined but equals "nothing"? (not assigned any value)

In this situation replace does not work.

Local $sRes
Local $sText = " The cat sat on the mat."
Local $aSearch[4][2] = [["cat", "dog"],["the", "a"],["mat", "rug"],["sat ", ""]]

$sRes = $sText & @CRLF

For $i = 0 To UBound($aSearch) - 1
    $sText = StringRegExpReplace($sText, $aSearch[$i][0], $aSearch[$i][1])
    $sRes &= $sText & @CRLF
Next

MsgBox(0, "StringRegExpReplace", $sRes)
;ConsoleWrite($sRes & @CRLF)

The expected results obtained from this example is:-

The cat sat on the mat.

The dog sat on the mat.

The dog sat on a mat.

The dog sat on a rug.

The dog on a rug.

Note - The default, case-sensitivity, is working. eg. Match on "the" but no match on "The"

I hope this example helps you realize why your script is not performing as you expect.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...