Skip to content
Advertisement

how to extract instagram username from string

I have an input field and my users are entering their instagram username in various formats

JavaScript

how can I extract username only?

with

JavaScript

I can extract from the URL. not sure how to search for whatever is after @

Advertisement

Answer

You want a regex that matches either @ or various forms of the URL version as a prefix to the username, followed by an optional forward-slash.

Something like this

JavaScript

Breaking it down

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement