cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
StevieC
Helper III
Helper III

Reg Exp to match characters ANYWHERE in string

I want to see if a special character appears anywhere in a string so I have the reg exp: [!$%]+ this works fine here Online regex tester

 

But in Power Apps this only matches if the string only contains a ! or $ - ie it matches  !$!!$!$! 0r ! or $$$ but not !try or test$

code: If(IsMatch(DataCardValue2.Text, "[!$]+"), Set(vError, true), Set(vError, false))

 

Any ideas what's going wrong?!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@StevieC 

Please consider changing your Formula to the following:

    Set(vError, !IsBlank(Match(DataCardValue2.Text, "[!$%]").FullMatch))

This will set your vError to true if there is a match of any one of the characters in the string and false if not.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

10 REPLIES 10
yashag2255
Dual Super User II
Dual Super User II

Hi @StevieC 

 

You can use the in operator to achieve your needs. You can write the expression as below:

 

If("%" in DataCardValue2.Text,Set(vError, true), Set(vError, false))

 

Here, you have to replace % with the special character you are looking for.

 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

RandyHayes
Super User III
Super User III

@StevieC 

Please consider changing your Formula to the following:

    Set(vError, !IsBlank(Match(DataCardValue2.Text, "[!$%]").FullMatch))

This will set your vError to true if there is a match of any one of the characters in the string and false if not.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

Perfect - thanks Randy.  Much neater way of setting the Bool too!.

Quick follow up - how would i get the following to work:

 

Set(varError, !IsBlank( Match(DataCardValue2.Text, "([!$%])").FullMatch Or IsMatch(DataCardValue2.Text, "^[^a-z]+$")))

 

The looks for the special characters OR all the text being in CAPS

cheers 🙂

RandyHayes
Super User III
Super User III

@StevieC 

I believe you are saying you want to make sure the text entered is all UpperCase CAPS?  Maybe I have it backward.

If so, then set your formula to:

Set(varError, 
   !IsBlank(Match(TextInput3.Text, "[!$%]").FullMatch) || 
   !IsBlank(Match(TextInput3.Text, "[a-z]").FullMatch)
)

If it was the opposite, and all should NOT be Uppercase, then use this formula:

Set(varError, 
   !IsBlank(Match(TextInput3.Text, "[!$%]").FullMatch) || 
   !IsBlank(Match(TextInput3.Text, "[A-Z]").FullMatch)
)

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Not quite either - more the second one though! I dont want ALL caps - so I dont want ABC or ABC! or A!BC OR !!! but Abc or aBc or abc is fine

 

The second option you gave above is true for ABC but also for ABc

 

cheers

RandyHayes
Super User III
Super User III

@StevieC 

Okay...got it now.  And that makes things a little simpler (for some reason....I consider myself a "begintermediate" with regular expressions, so I struggle through them but use them often).

Use this formula:

Set(varError, 
   !IsMatch(DataCardValue2.Text, "^(?=.*[A-Z])(?=.*[a-z])(?!.*[!$%]).*")
)

I vetted this out here and it seems to meet all the conditions you mention.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Thats amazing - just had to add a slight tweak to allow numbers, but its all working perfectly now - thanks for all your help, ill pick though it and understand what it all means 🙂

RandyHayes
Super User III
Super User III

@StevieC 

Excellent!! When you figure it out, let me know...LOL 🤣🤣  Actually, that one was fairly understandable in my head and again, I'm still a begintermediate with reg ex.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (29,892)