Remove everything after first phrase

I have been trying to figure out how to remove everything after the first phrase. Following is an example:

“<1space><1space><1space><1space>Woodworks and Craft<1space><1space><1space><1space><1space><1space><1space><1space>Metal Works<1space><1space><1space><1space><1space><1space><1space><1space><1space><1space><1space><1space>Steel Works<1space><1space><1space><1space><1space><1space><1space><1space>”

The spaces are not fixed and the phrases are dynamic.

How do i remove everything after Woodworks and Craft please?

Use → Regex for this -->Woodworks and Craft

I know have to use regex. I don’t know the pattern to use

@CGhoST Try this. Find below workflow (2.5 KB)

Variable of type String Output = System.Text.RegularExpressions.Regex.Replace(Input, "(?<=Woodworks\s+and\s+Craft).*",String.Empty)
1 Like

Thank you but as i mentioned Woodworks and Craft is dynamic

@CGhoST Can you share sample two different Phrases

I was trying to put spaces but after save they were being removed so i <1space>

Another example:

<1space><1space><1space><1space><1space><1space><1space>Volleyball and Netball<1space><1space><1space><1space><1space><1space><1space><1space>Soccer<1space><1space><1space><1space><1space><1space><1space><1space>Cricket<1space><1space><1space><1space><1space><1space>Basketball<1space><1space><1space><1space><1space><1space>Tennis<1space><1space><1space><1space><1space><1space>

Wish everything removed after Volleyball and Netball

I am ok with the spaces after Volleyball and Netball but want everything removed from Soccer on wards in the above example and everything after Metal Works in the first example.

Everything is dynamic

@CGhoST I hope there is always and between first two words. Is that right ?

No unfortunately. It could be Volleyball Netball even

@CGhoST 1space count will always be same or will it going to vary. I see that before first phrase there were total 7 <1space><1space><1space><1space><1space><1space><1space>Volleyball and Netball

The spaces will vary also

you mean you just want to remove all the spaces after each phrase?

Remove everything after first phrase

you want result to look like this? (just remove space )
“<1space><1space><1space><1space> Woodworks and Craft
<1space><1space><1space><1space><1space><1space><1space> Metal Works <1space><1space><1space><1space><1space><1space><1space><1space><1space><1space><1space><1space> Steel Works <1space><1space><1space><1space><1space><1space><1space><1space>”

or this?
“<1space><1space><1space><1space> Woodworks and Craft

This please

System.Text.RegularExpressions.Regex.Replace(txt, "(?s)(?<="+phrase+").*", "")

Example (when phrase = “Woodworks and Craft”)


Can you try the following expression?



Wow. Amazing.

Thank you so much :smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.