Using regex to match a sting in a replace function

%3CLINGO-SUB%20id%3D%22lingo-sub-1097890%22%20slang%3D%22en-US%22%3EUsing%20regex%20to%20match%20a%20sting%20in%20a%20replace%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1097890%22%20slang%3D%22en-US%22%3E%3CP%3EHoping%20someone%20can%20help%20me%20with%20an%20issue.%26nbsp%3B%20I%20have%20some%20text%20that%20comes%20from%20an%20RSS%20feed%20that%20I%20post%20to%20Yammer%20using%20Flow.%26nbsp%3B%20The%20source%20randomly%20includes%20text%20between%20square%20brackets.%26nbsp%3B%20The%20text%20is%20different%20but%20it's%20always%20between%20squire%20brackets%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ee.g.%26nbsp%3BReconsider%20your%20need%20to%20travel%20%5B%2Fconsular-services%2Ftravel-advice-explained%5D%20due...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20simply%20remove%20the%20text%20in%20the%20square%20brackets%20along%20with%20the%20brackets.%26nbsp%3B%20If%20I%20use%20a%20replace%20and%20%22hard%22%20code%20the%20string%20to%20remove%20(string2%20in%20the%20replace%20function)%20it%20works%20fine%20e.g.%26nbsp%3B%3CFONT%20face%3D%22inherit%22%3Ethe%20%3C%2FFONT%3Eexpression%3CFONT%20face%3D%22inherit%22%3E%26nbsp%3Bthat%20works%20is%20below.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Ereplace(variables(%3C%2FSPAN%3E%3CSPAN%3E'String'%3C%2FSPAN%3E%3CSPAN%3E)%2C%3C%2FSPAN%3E%3CSPAN%3E'%5B%2Fconsular-services%2Ftravel-advice-explained%5D%20'%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3CSPAN%3E'New%20Text'%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22inherit%22%3EHowever%20if%20I%20try%20to%20use%20a%20regex%20that%20looks%20for%20anything%20between%20square%20brackets%20in%20place%20of%20the%20%22hard%22%20coded%20string%20it%20fails.%26nbsp%3B%20I%20know%20your%20going%20to%20say%20i%20need%20to%20escape%20the%20%3C%2FFONT%3Esquare%3CFONT%20face%3D%22inherit%22%3E%26nbsp%3Bbrackets%20I%20am%20aware%20of%20this%20and%20tried%20a%20few%20different%20combinations.%26nbsp%3B%20I%20even%20tested%20the%20expressions%20on%20various%20regex%20test%20tools%20and%20the%20%3C%2FFONT%3Eexpression%3CFONT%20face%3D%22inherit%22%3E%26nbsp%3Bmatches%20but%20not%20in%20Flow.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22inherit%22%3Eexamples%20of%20regex%20strings%20i%20tried%20are%20below.%26nbsp%3B%20They%20all%20work%20in%20the%20various%20regex%20%3C%2FFONT%3Etesting%3CFONT%20face%3D%22inherit%22%3E%26nbsp%3Btools%20and%20websites%20but%20Flow%20doesn't%20work.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%5C%5B(%5B%5E%5C%5D%5C%5B%5Cr%5Cn%5D*)%5C%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%5C%5B(.*%3F)%5C%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E(%5C%5B(%3F%3A%5C%5B%3F%3F%5B%5E%5C%5B%5D*%3F%5C%5D))%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%5C%5B(%5B%5E%5D%5D%2B)%5C%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIs%20there%20a%20special%20way%20to%20use%20a%20regex%20in%20a%20replace%20expression%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAre%20regex%20even%20supported%20in%20a%20replace%20expression%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAm%20I%20missing%20something%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1097890%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Flow%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1098010%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20regex%20to%20match%20a%20sting%20in%20a%20replace%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1098010%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F393307%22%20target%3D%22_blank%22%3E%40lfkentwell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegEx%20has%20some%20limited%20support%20in%20Plumsail%20and%20AquaForest%20PDF%20connectors%2C%20but%20nothing%20else%20that%20I%20can%20see.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPerhaps%20the%20easiest%20workaround%20is%20to%20pass%20the%20RSS%20feed%20output%20through%20Excel%20Online%20and%20use%20this%20formula%20to%20remove%20the%20brackets%20and%20text%20between.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3DLEFT(A1%2CFIND(%22%5B%22%2CA1)-1)%26amp%3BRIGHT(A1%2CLEN(A1)-FIND(%22%5D%22%2CA1)-1)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ESo%20basically%20have%20the%20RSS%20feed%20output%20inserted%20into%20cell%20A1%20and%20the%20formula%20can%20be%20in%20A2.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20formula%20then%20removes%20the%20bracketed%20info%20and%20you%20can%20retrieve%20the%20result%20of%20A2%20and%20pass%20it%20to%20Yammer.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EA%20few%20extra%20steps%20but%20you'll%20get%20the%20result.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EHopefully%20that%20gives%20you%20something%20to%20play%20with%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ECheers%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EDamien%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EEDIT%3A%20Forgot%20to%20mention%2C%20make%20A1%20and%20A2%20into%20a%20table%20as%20the%20Excel%20connector%20will%20need%20to%20reference%20it.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1098023%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20regex%20to%20match%20a%20sting%20in%20a%20replace%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1098023%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20again%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F393307%22%20target%3D%22_blank%22%3E%40lfkentwell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFurther%20to%20my%20last%20message%2C%20here's%20a%20screen%20shot%20of%20the%20process%20I%20was%20describing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F164415i479C3D20304C8634%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3CP%3EDamien%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1100079%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20regex%20to%20match%20a%20sting%20in%20a%20replace%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1100079%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89704%22%20target%3D%22_blank%22%3E%40Damien%20Rosario%3C%2FA%3E%26nbsp%3Bthanks%20for%20the%20input.%26nbsp%3B%20After%20literally%20wasting%20half%20a%20day%20trying%20to%20get%20regex%20to%20work%20i%20found%20one%20entry%20in%20Google%20that%20appears%20to%20indicate%20regex%20is%20not%20supported%20natively.%26nbsp%3B%20Can't%20imagine%20why%20its%20not%20but%20there%20you%20go.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20suggestion%20I%20was%20able%20to%20get%20it%20to%20work%20within%20Flow%20using%20splits%20and%20concatenates%20its%20just%208%20steps%20long%20which%20seem%20crazy%20when%20it%20could%20be%20done%20in%20one%20replace%20if%20only%20regex%20was%20supported.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1100323%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20regex%20to%20match%20a%20sting%20in%20a%20replace%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1100323%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F393307%22%20target%3D%22_blank%22%3E%40lfkentwell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYup%2C%20not%20currently%20supported%20which%20is%20a%20shame.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYeah%20the%20workaround%20you%20mentioned%2C%20or%20mine%2C%20etc%20are%20the%20way%20to%20go%20for%20now.%20It%20gets%20a%20result!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20wishes%20with%20your%20Power%20Automate%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3CP%3EDamien%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1100468%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20regex%20to%20match%20a%20sting%20in%20a%20replace%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1100468%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89704%22%20target%3D%22_blank%22%3E%40Damien%20Rosario%3C%2FA%3E%26nbsp%3BAppreciate%20the%20support.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

Hoping someone can help me with an issue.  I have some text that comes from an RSS feed that I post to Yammer using Flow.  The source randomly includes text between square brackets.  The text is different but it's always between squire brackets

 

e.g. Reconsider your need to travel [/consular-services/travel-advice-explained] due...

 

I want to simply remove the text in the square brackets along with the brackets.  If I use a replace and "hard" code the string to remove (string2 in the replace function) it works fine e.g. the expression that works is below.

 

replace(variables('String'),'[/consular-services/travel-advice-explained] ','New Text')

 

However if I try to use a regex that looks for anything between square brackets in place of the "hard" coded string it fails.  I know your going to say i need to escape the square brackets I am aware of this and tried a few different combinations.  I even tested the expressions on various regex test tools and the expression matches but not in Flow.

 

examples of regex strings i tried are below.  They all work in the various regex testing tools and websites but Flow doesn't work.

 

\[([^\]\[\r\n]*)\]

\[(.*?)\]

(\[(?:\[??[^\[]*?\]))

\[([^]]+)\]

 

Is there a special way to use a regex in a replace expression?

Are regex even supported in a replace expression?

Am I missing something?

 

 

5 Replies

Hi @lfkentwell 

 

RegEx has some limited support in Plumsail and AquaForest PDF connectors, but nothing else that I can see.

 

Perhaps the easiest workaround is to pass the RSS feed output through Excel Online and use this formula to remove the brackets and text between.

 

=LEFT(A1,FIND("[",A1)-1)&RIGHT(A1,LEN(A1)-FIND("]",A1)-1)

 

So basically have the RSS feed output inserted into cell A1 and the formula can be in A2. 

 

The formula then removes the bracketed info and you can retrieve the result of A2 and pass it to Yammer.

 

A few extra steps but you'll get the result.

 

Hopefully that gives you something to play with?

 

Cheers

Damien 

 

EDIT: Forgot to mention, make A1 and A2 into a table as the Excel connector will need to reference it.

Hi again @lfkentwell 

 

Further to my last message, here's a screen shot of the process I was describing.

 

clipboard_image_0.png

 

Cheers

Damien

@Damien Rosario thanks for the input.  After literally wasting half a day trying to get regex to work i found one entry in Google that appears to indicate regex is not supported natively.  Can't imagine why its not but there you go.

 

Thanks for your suggestion I was able to get it to work within Flow using splits and concatenates its just 8 steps long which seem crazy when it could be done in one replace if only regex was supported.

Hi @lfkentwell 

 

Yup, not currently supported which is a shame.

 

Yeah the workaround you mentioned, or mine, etc are the way to go for now. It gets a result!

 

Best wishes with your Power Automate work.

 

Cheers

Damien

 

 

@Damien Rosario Appreciate the support.