I need to find a string like this @[0000:0000:Username] in a text.
Then I need to extract the first number sequence (user-id) and the Username. Then I need to replace them with a link.
I'm able to extract the first number sequence but the Username is variable. It can have multiple words (and spaces) but it can also be a single word e.g "John", "John Doe", "John Doe Junior".
The Username can contain alphanumeric characters, periods, underscores and dashes.
This is what I have now with username up to 4 words:
/@\[(\d*):\d*:(\S*|\S*\s*\S*\s*\S*\s*\S*)\]/
And this is the link I'd like to create:
<a href="http://www.facebook.com/user-id/" target="_blank">Username</a>
I'm trying to it like this:
<a href="http://www.facebook.com/$1/" target="_blank">$2</a>
This works fine if only one match is found. As soon as there's more matches it messes up.
Any help would be greatly appreciated.
Obviously this doesn't work.. It does (for the examples shown in the question anyway). I think the question could be improved by explaining all your requirements, @Ziggy.