How to match a URL containing emojis using a regex?

后端 未结 3 910
无人及你
无人及你 2021-01-07 13:10

How can I write a regular expression to match URLs that contain emojis? The regex should match ordinary alphanumeric URLs along with URLs containing emojis in the domain nam

3条回答
  •  孤独总比滥情好
    2021-01-07 14:02

    This regular expression matches ordinary alphanumeric URLs along with URLs containing emojis in the domain name, path and/or parameters:

    https?:\/\/(www\.)?[-a-zA-Z0-9\u1F60-\uFFFF@:%._\+~#=]{2,256}\.[a-z]{2,256}\b([-a-zA-Z0-9\u1F60-\uFFFF@:%_\+.~#?&//=]*)
    

    Try it out here: https://regexr.com/3gsl9

    Notice that the range of unicode characters that include emojis (i.e. \uXXXX-\uXXXX) might need to be updated in future when new emojis will be added.

提交回复
热议问题