I have a string like this:
var str = 'anything <span><a href="http://www.example.com/classname/methodname/arg1/arg2" target="_blank">...www.example.com/clas</a> </span> anything';
I want this output:
var newstr: 'anything http://www.example.com/classname/methodname/arg1/arg2 anything';
How can I do that? Actually I almost can do that using multiple str_replace()
. But I want to know how can I do that using regex?
str.str_replace('<span><a href="', '');
str.str_replace('" target="_blank">', '');
str.str_replace('</a> </span> ', '');
// output:
anything http://www.example.com/classname/methodname/arg1/arg2...www.example.com/clas anything
Well, As you see, I just can't remove ...www.example.com/clas
in the my output.
Note: anything
in the example could be any words/sentences. Btw, in reality there is Persian characters.
Edit1: Here is an example:
I want to replace this:
This <span><a href="www.example.com/classname/methodname/arg1/arg2/" target = "_blank"> ... www.example.com/clas</a> </span> is very good.
With this:
This www.example.com/classname/methodname/arg1/arg2/ is very good.
Edit2: Also I need to the value of that link. Something like this pattern:
[LinkName](LinkAddress)
Note: Just I want to create the above patter if the value of that link don't be "untitled".
Example1:
var str = 'anything <span><a href="http://www.example.com/classname/methodname/arg1/arg2" target="_blank">website name</a> </span> anything';
I want this:
var newstr: 'anything [website name](http://www.example.com/classname/methodname/arg1/arg2 anything)';
Example2:
var str = 'anything <span><a href="http://www.example.com/classname/methodname/arg1/arg2" target="_blank">untitled</a> </span> anything';
I want this:
var newstr: 'anything http://www.example.com/classname/methodname/arg1/arg2 anything';