Use Regex to remove items

Hi,
Please help with the below

From a string I want to remove any item which is null or blank.

Example:
" Name=“MLFgg” EmpID=“1234” IsFlag="" Country=“India”"

Here I want to remove IsFlag="" as it contains nothing

The final string will contain
" Name=“MLFgg” EmpID=“1234” Country=“India”"

So where ever there is null I want to remove that part. Please help

Hi @Sana_Afreen

Try thie regex pattern

[A-Za-z""=]+(?<="")

You can use replace activity for this

Regards

Nived N

Happy Automation

@Sana_Afreen - As an alternate.you can try this…

StrReplace= image

StrReplace is string…

Write Line = StrInput.Replace(StrReplace,"")

Output:

image

1 Like

Hi,
There is one additional space after replace.
In this example there are 2 space before Country. How to remove that space also

There is one additional space after doing replace.
In this example there are 2 space before Country. How to remove that space also.
In this example We have to remove IsFalg=''' where is space

Hi @Sana_Afreen

Try like this

[A-Za-z""=]+(?<="")[\s]+

Hi @Sana_Afreen,

So where ever there is null I want to remove that part.

As your string may also have more keys which do not have values in it, you can use the following matches and use .replace activity recursively in a for loop.

\s(?<EmptyKeys>\w{1,20}="")

  • Look for empty space,
  • Name the group as EmptyKeys,
  • Look for word characters of minimum length 1 and maximum of 20,
  • Look for equal sign and “”

This will take care of the extra spaces when you remove the matched strings.

Tested inputs
Case1: " Name=“MLFgg” EmpID=“1234” IsFlag="" Country=“India”"
Case2: " Name="MLFgg" EmpID=“” IsFlag="" Country="""

Outputs :
Case1: " Name=“MLFgg” EmpID=“1234” Country=“India”"
Case2:" Name="MLFgg" EmpID=“”"

Inputs: StringInput1.txt (66 Bytes) StringInput2.txt (49 Bytes)
Workflow: RegexRemove.xaml (15.2 KB)

Hope this helps!