I assume that the text "username1" is just a placeholder for what will eventually be an actual username. Assuming that,
- If the username is not allowed to have spaces, then just search for everything before the first space or comma (thus finding both "u1 likes this" and "u1, u2, and u3 like this").
- If it is allowed to have a space, it would probably be easier to wrap each username in it's own
span
tag server-side, before sending it to the client, and then just working with the span tags.