cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

extract substring using regex

Hi there,

 

I'm trying to extract a substring for text that is variable - both the string and the substring change, but while the structure of the string changes, the pattern of the substring remains the same - it just appears in different places depending on the string.

 

Example: Two strings

sdflkjsdlkjsdflksdjfldsfkj@123BOB23sdflkjsjdlfkjsdfkj

sdflkjsddjfldsfkj@4567SUE45sdflkjsjdlfkjsdfkjasdasdasd

 

I want to extract -123BOB23  and -4567SUE45 from each string using the same method.

I can use IsMatch to determine if the pattern exists with regular expressions, but IsMatch just checks for the pattern, it doesn't extract it for me.

 

I can't rely on Left/Mid/Right as the last digit of what I'm extracting changes, making it impossible to determine where it ends using those methods.

 

Ideally I need something like IsMatch to provide a way to both match the pattern and extract the substring for me....

Any ideas?

 

Kind regards,


R

1 ACCEPTED SOLUTION

Accepted Solutions
v-yamao-msft
Community Support
Community Support

Hi Russel_Thomas,

 

I am afraid currently there might not be such a function can be used to extract substring.

 

May you consider to submit a request at PowerApps ideas Forum for this function:
https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

 

I will report it on my side and keep an eye on this function, I will back to you if I got any updates.

 

Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yamao-msft
Community Support
Community Support

Hi Russel_Thomas,

 

I am afraid currently there might not be such a function can be used to extract substring.

 

May you consider to submit a request at PowerApps ideas Forum for this function:
https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

 

I will report it on my side and keep an eye on this function, I will back to you if I got any updates.

 

Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable
Anonymous
Not applicable

Have you guys comes up with any solution to this problem yet?

I realise this is a really old post but in case someone is searching for this, the answer is to use named groups like so.

image.png

In this example, this is the formula we would use.

Match( "sdflkjsdlkjsdflksdjfldsfkj@123BOB23xx", "(\d+)(?!.*\@)(?<EmailSuffix>.*)" ).EmailSuffix

I have a similar problem @timl . I am trying to automate customer emails and rejecting them if the unique customer number is not in the subject line. The customer number format is "HR123456-7" Starting with "HR*", has a number <99999 and >1,000000 so only six digits, and ends with a dash and a version number straight after the dash (very few go past 9 versions).

 

At the moment I am using a simple conditions in the flow "starting with HR" and "contains -". But I want the condition to be fool proof.

Maybe I need to use a different formula type to match a substring in a string?

 

(I can cope with OR conditions so I can duplicate and include the solution with 2 integers for the version number.)

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,757)