Rremove the space before the keyword or remove the word from an array of sentences and return the new array

Hi all,

The (successful) football (club(s)) (managers)

I have an array out of above sentence.the array is basically splitting above words.

ArrOfWords = {“the”,”Successful”,”football”,”club”,”s”,”managers”}

Out of the above array I have generated a set of combinations as below.
Combinations array
1.the football club
2.the successful football club s
3.the football s
4.The football s manager
5.football club s manager

Result array.
1.football
2.the successful football clubs
3.the football
4.the football manager
5.football clubs manager

From the first array I know the word before letter “s” is club.
So I have to check in the combinations array

If Letter “s”is present in combination and the word before it is club.
Then I have to remove space between them.

But if letter is ‘s’ and the before word is something else then I have to delete word in that sentence.

The final output is resultsarray

Can someone help with the query please

@ppr @Yoichi Hi guys good morning can you please help out here.thanks in advance

Hi,

How about the following?

arrRes = arrRes.Select(Function(s) System.Text.RegularExpressions.Regex.Replace(s,"(?<=\bclub) (?=s\b)| s\b","")).ToArray

Regards,

Hi @Yoichi

Here the club and s are common but they might get changed to some other words.

Can we do something to pass both club and s in variable to the above expression please.

Which would make dynamic to use it for any combinations at runtime.

Hi,

How about the following?

keywords = {"club","apple"}

then

 arrRes = arrRes.Select(Function(s) System.Text.RegularExpressions.Regex.Replace(s,"(?<=\b("+String.Join("|",keywords)+")) (?=s\b)| s\b","")).ToArray

The above assumes keywords don’t include special character of regex.

Regards,

Sorry @Yoichi i might have confused you.

For the first expression you have given.

Stringvar1 will be club
Stringvar2. Will be s

So in the first expression you gave I need to pass stringvar1 and stringvar2 in its respective places .

I hope now my question is clear.

All right. Can you try the following expression?

arrRes.Select(Function(s) System.Text.RegularExpressions.Regex.Replace(s,"(?<=\b"+Stringvar1+") (?="+Stringvar2+"\b)| "+Stringvar2+"\b","")).ToArray

Regards,

1 Like

Hi @Yoichi Sorry for the delay this works thank you <3

1 Like

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