cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
skini76
Frequent Visitor

How to use regular expression to compare two strings in PowerApp ?

string1 = "Banana,Apple,Orange"

string2 = "Apple, Grapes, Plum"

 

In the above case, Apple is common between two strings, so the result of comparison should be True.

Can we achieve this using regular expression in PowerApp ?

 

7 REPLIES 7
Super User
Super User

Re: How to use regular expression to compare two strings in PowerApp ?

@skini76 

You can do this another way.  Regular expressions won't work here.

 

Put this code in your app.  You have the option of returning the values as a Collection (mySolutionCollection) or a text variable (mySolutionText).

 

//create collections
ClearCollect(myCol1,Split("Apples, Oranges, Bananas", ","));
ClearCollect(myCol2,Split("Apples, Oranges, Plum",","));

//get matches stored in a Collection
ClearCollect(
    mySolutionCollection,
        ShowColumns(
            Filter(
                AddColumns(
                myCol1,
               "MatchFound",If(!IsBlank(LookUp(myCol2,Result=myCol1[@Result])),true,false)
            ),
           MatchFound=true),
       "Result")
);

//get matches stored in a SET variable
Set(
    mySolutionText,
    Left(
        Concat(mySolutionCollection,Result&","),
        Len(Concat(mySolutionCollection,Result&","))-1
    )
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Community Support
Community Support

Re: How to use regular expression to compare two strings in PowerApp ?

Hi @skini76 ,

 

I don't think that's going to happen.

As an alternative workaround:

1. split the string by "," and check if the item in string A exists in String B

 

ClearCollect(myCol1,Split("Apples, Oranges, Bananas", ","));
ClearCollect(myCol2,Split("Apples, Grapes, Plum",","));
ClearCollect(myCol3,ForAll(myCol1, Result in myCol2))

 

2. if there is a true in mycol3, that mean there is a match.

Set true in myCol3 to Text of label.

Best regards,

Sik

 

skini76
Frequent Visitor

Re: How to use regular expression to compare two strings in PowerApp ?

thanks, how to read the content of myCol3 ? myCol3(0).Value ? What is the syntax ?

Community Support
Community Support

Re: How to use regular expression to compare two strings in PowerApp ?

Hi @skini76 ,

 

Set text property of Label:

true in myCol3.Value

If there is a match, mycol3 collection will have a "true" value, so we just check if "true" is in the mycol3.

Sik

Highlighted
skini76
Frequent Visitor

Re: How to use regular expression to compare two strings in PowerApp ?

I tried the below e.g., it is not working

 

ClearCollect(
    myCol1,
    Split(
        "Private, Public, Foreign, Small Finance, Local, Payments",
        ","
    )
);
ClearCollect(
    myCol2,
    Split(
        "Foreign, Private, BigData",
        ","
    )
);
ClearCollect(myCol3,ForAll(myCol1, Result in myCol2));

skini76
Frequent Visitor

Re: How to use regular expression to compare two strings in PowerApp ?

I tried the below e.g using your logic, but result is not as expected.

 

//create collections
ClearCollect(myCol1,Split("Private, Public, Forign, Local, Payment", ","));
ClearCollect(myCol2,Split("Public, Local, Plum", ","));
//get matches stored in a Collection
ClearCollect(
    mySolutionCollection,
        ShowColumns(
            Filter(
                AddColumns(
                myCol1,
               "MatchFound",If(!IsBlank(LookUp(myCol2,Result=myCol1[@Result])),true,false)
            ),
           MatchFound=true),
       "Result")
);
//get matches stored in a SET variable
Set(
    mySolutionText,
    Left(
        Concat(mySolutionCollection,Result&","),
        Len(Concat(mySolutionCollection,Result&","))-1
    )
); Notify (mySolutionText);
Community Support
Community Support

Re: How to use regular expression to compare two strings in PowerApp ?

@skini76 

Just modify as below, add a space behind the comma.

ClearCollect(
    myCol1,
    Split(
        "Private, Public, Foreign, Small Finance, Local, Payments",
        ", "
    )
);
ClearCollect(
    myCol2,
    Split(
        "Foreign, Private, BigData",
        ", "
    )
);
ClearCollect(myCol3,ForAll(myCol1, Result in myCol2));

Sik

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Attending MBAS? Claim your badge

Attending MBAS? Claim your badge

Whether you’re streaming the digital event live, or watching on-demand, claim your attendee badge to sport on your profile.

‘Better Together’ T-Shirt Contest – Winner Announced!

‘Better Together’ T-Shirt Contest – Winner Announced!

And the winner is...

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Power Platform 2020 release wave 1 plan

Power Platform 2020 release wave 1 plan

Features releasing from April 2020 through September 2020

‘Better Together’ Integration Forum Launch

‘Better Together’ Integration Forum Launch

We're launching a how-to forum where you can learn about how Power BI integrates with other Power Platform products.

Emergency Response & Monitoring Solution

Emergency Response & Monitoring Solution

Microsoft has created a regional government emergency response and monitoring solution that is built on Power Apps and Power BI.

Top Solution Authors
Top Kudoed Authors
Users online (6,082)