regex - php regular expression string replace -
i have string json response script:
"lorem ipsum dolor sit amet, consectetur adipiscing elit, http://unknown/string/in/unknown/place/ , sed eiusmod tempor incididunt ut labore et dolore magna aliqua"
is there way replace empty string using regular expression , php preg_replace?
i'm not familiar regular expression, provide example? need remove substring starting 'http' , finishing space, if possible.
thanks
something like
preg_replace("/http\s+\s,/", "","lorem ipsum dolor sit amet, consectetur adipiscing elit, http://unknown/string/in/unknown/place/ , sed eiusmod tempor incididunt ut labore et dolore magna aliqua" );
will give output as
lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua
regex /http\s+\s,/
\s
matches other space\s
matches space
edit
a better solution like
/http\s+(\s,|$)/
so link can apear anywhere in string @ end.
example
preg_replace("/http\s+(\s,|$)/", "","lorem ipsum dolor sit amet, consectetur adipiscing elit, http://unknown/string/in/unknown/place/" ); => lorem ipsum dolor sit amet, consectetur adipiscing elit,
Comments
Post a Comment