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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (2,765)