Skip to content
Advertisement

preg_replace twitter url not working with question mark php

I have created the next function to replace an url by a div with its id.

JavaScript

It works well when I use this type of url

JavaScript

but it retrieve an excedent ?s=20 when I use this url

JavaScript

How can I remove this ?s=20 text, in order to make work my function ? Anything I know is I need to improve my regex pattern. thank you.

Advertisement

Answer

If you want just regex:

JavaScript

Because ? is not a digit so it will seperate with (.*), this mean every thing rest and in this case is ?s=xyz, last question mark ? is to say that is can exist or not.

Learn regex

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