1

I want to remove multiple hashtags from the end of a paragraph.

#abc #def This is a test paragraph. #ads I only want to remove the hashtags after the full stop at the end and keep the hashtag at the center. These hashtags should be removed. #ads #ime #abc

I tried this regular expression /. #([^\]*)/g But it is removing everything from the full stop of the first sentence because the full stop is followed by #ads. How should I remove the hashtags at the end of the paragraph?

I'm using a no-code platform to work. So there are limitations for me to write code. But I'm using the replaceRegex function for doing this.

What I have

var.a = "#abc #def This is a test paragraph. #ads I only want to remove the hashtags after the full stop at the end and keep the hashtag at the center. These hashtags should be removed. #ads #ime #abc"

Function

{{replaceRegex var.a '/\. #([^\\]*)/g' " "}}

Actual Result

#abc #def This is a test paragraph

Expected Result

#abc #def This is a test paragraph. #ads I only want to remove the hashtags after the full stop at the end and keep the hashtag at the center. These hashtags should be removed.
Shibin
  • 85
  • 3
  • Does this answer your question? [Find Last Occurrence of Regex Word](https://stackoverflow.com/questions/38490160/find-last-occurrence-of-regex-word) – online Thomas Jun 29 '21 at 08:28
  • regex language is different depending on the programming language used. Please specify your coding language in the tags of your question. – LaytonGB Jun 29 '21 at 08:56
  • @LaytonGB The platform I use works on javascript. – Shibin Jun 29 '21 at 09:41

2 Answers2

0

According to your description, this regex might work:

\. #[^\\.]*$
//      ^  ^

It adds a . to your exclusion list and an end enchor $ at the end

Using your script:

{{replaceRegex var.a '/\. #[^\\.]*$/g' "."}}
Hao Wu
  • 17,573
  • 6
  • 28
  • 60
0

This is an alternative way to do the job: Rather than finding the end of the string, it finds the text-groups starting with # that do not have any other character groups after them.

(?<=\.\s+)(#[a-zA-Z]+ *)+(?! *[^\s])

You can see the results here: https://regex101.com/r/1JpJPT/1

LaytonGB
  • 1,384
  • 1
  • 6
  • 20
  • It worked. Is there any way to remove the first hashtags from the sentence? – Shibin Jun 29 '21 at 12:46
  • Your question specifically shows you want to keep those hashtags. If you want the answer to a new question, you should mark an answer as the solution to this question and then ask a new question. – LaytonGB Jun 29 '21 at 13:04