Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Regex: remove non-adjacent duplicate hashtags (updated)

by haukex (Archbishop)
on Jul 23, 2022 at 13:10 UTC ( [id://11145666]=note: print w/replies, xml ) Need Help??


in reply to Regex: remove non-adjacent duplicate hashtags

You need to use \1 instead of $1, see perlre.

You may also want to move the \s? out of the capture group.

Update: Plus, what LanX said about using a lookahead!

Replies are listed 'Best First'.
Re^2: Regex: remove non-adjacent duplicate hashtags
by element22 (Novice) on Jul 23, 2022 at 13:24 UTC
    Thanks, it works. Here's my more elaborated version:

    $tags=~s/(#\S{2,}\b)(.*\s?)(\1)(\s?.*)/$3$2$4/g;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-24 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found