web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Replace text and group...
Power Apps
Answered

Replace text and group of numbers using Regex

(0) ShareShare
ReportReport
Posted on by 121

Hi all,

I've been trying to find a solution for this but nothing I can come up with seem to work.

 

I have a bunch of text coming in that can look like this

 

Hello, this i a whole lot of text that contain the word APPLE, APPLE123456 and it can contain various versions of the group APPLE and 6 digits put together, for example APPLE654321 and maybe also APPLE342514. NOTE, it is of importance that only the APPLE followed by the 6 digits is replaced, not every instance of the word APPLE.

 

What I need is to find a way to substitute APPLE999999 (so apple and the 6 following digits) with another word but keeping the digits.

For instance, instead of APPLE I want it to say REPLACED followed by the digits inside of a textbox.

 

I've been testing various things with regex, but since I don't know regex or how to properly incorporate it into powerapps I've yet to get a good result.

Substitute(Label1.Text, "([^APPLE\d[0-9]{6}$])", "REPLACED"& "[0-9]")

 

Anyone got an idea if this can be accomplished somehow?

Categories:
  • CU18061035-1 Profile Picture
    18 Microsoft Employee on at

    hy @drawser 

     

    You can create a function on a button or another control to perform the action when triggered. The function will split the text into parts, check for the pattern, and reconstruct the text with the necessary replacements.

    ClearCollect(MyTextCollection, {Text: "Hello, this is a whole lot of text that contains the word APPLE, APPLE123456, and it can contain various versions of the group APPLE and 6 digits put together, for example, APPLE654321 and maybe also APPLE342514."})
    
    UpdateContext({UpdatedText: Concatenate(
     ForAll(
     Split(First(MyTextCollection).Text, " "),
     If(
     Left(ThisRecord.Result, 5) = "APPLE" And Len(ThisRecord.Result) = 11,
     "REPLACED" & Mid(ThisRecord.Result, 6, 6),
     ThisRecord.Result
     ),
     " "
     )
    )});
    

     

     Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • drawser Profile Picture
    121 on at

    Thanks for the input, altho it throws me an error on the UpdateContext: "Invalid Number of Arguments, recieved 3, expected 2"

     

    ClearCollect(
     MyTextCollection,
     {Text: "Hello, this is a whole lot of text that contains the word APPLE, APPLE123456, and it can contain various versions of the group APPLE and 6 digits put together, for example, APPLE654321 and maybe also APPLE342514."}
    );
    UpdateContext({UpdatedText: Concatenate(
     ForAll(
     Split(First(MyTextCollection).Text, " "),
     If(
     Left(ThisRecord.Value, 5) = "APPLE" And Len(ThisRecord.Value) = 11,
     "REPLACED" & Mid(ThisRecord.Value, 6, 6),
     ThisRecord.Value
     ),
     " "
     )
    )})

     

     

  • CU18061035-1 Profile Picture
    18 Microsoft Employee on at

    hey @drawser 

     

    can u try this modification:

    UpdateContext({
     UpdatedText: Concatenate(
     ForAll(
     Split(First(MyTextCollection).Text, " "),
     If(
     Left(ThisRecord.Result, 5) = "APPLE" And Len(ThisRecord.Result) = 11,
     "REPLACED" & Mid(ThisRecord.Result, 6, 6) & " ",
     ThisRecord.Result & " "
     )
     )
     )
    });
    

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • drawser Profile Picture
    121 on at

    Thanks, that doesn't throw me an error, but it doesn't replace the word apple either.

     

    The text string comes out just as it does in original form

  • Verified answer
    CU18061035-1 Profile Picture
    18 Microsoft Employee on at

    another approach:

    UpdateContext({
     UpdatedText: Concatenate(
     ForAll(
     Split(First(MyTextCollection).Text, " "),
     If(
     Left(ThisRecord.Result, 5) = "APPLE" And 
     Len(ThisRecord.Result) >= 11 And 
     IsNumeric(Mid(ThisRecord.Result, 6, 6)),
     "REPLACED" & Mid(ThisRecord.Result, 6, 6) & " ",
     ThisRecord.Result & " "
     )
     )
     )
    });
    

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • drawser Profile Picture
    121 on at

    No, same thing there. It doesn't throw me an error but also the word APPLE is not being replaced.

    Is it working on your end?

  • drawser Profile Picture
    121 on at

    I seem to have figured this out, the UpdatedText is stored as a table, so you have to Concat that as well.

    Then it works.

     

    drawser_0-1715608729522.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 234 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard