how to use regular expression to change url in php [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
this is my url ....where i want to change 40px to 250px ...here 40px is dynamic...how to change it in php....using regex...here is a link below
http://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/40px-President_Barack_Obama.jpg
here is the things...what i tried
url="http://upload.wikimedia.org/wikipedia/commons/thumb /8/8d/President_Barack_Obama.jpg/40px-President_Barack_Obama.jpg";
var filename = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
so any possible soluation

Try to use preg-replace() like,
PHP
$url = "http://upload.wikimedia.org/wikipedia/commons/thumb /8/8d/President_Barack_Obama.jpg/40px-President_Barack_Obama.jpg";
echo $filename = preg_replace('/\.jpg\/\d+px-/', '.jpg/250px-',$url);
Javascript
url = "http://upload.wikimedia.org/wikipedia/commons/thumb /8/8d/President_Barack_Obama.jpg/40px-President_Barack_Obama.jpg";
var filename = url.replace(/\.jpg\/\d+px-/, '.jpg/250px-');
alert(filename);
Demo

Related

How to detect and replace values/parameters in URL on redirection [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
For clarification of my question, let me specify everything,
There are three links (link A and Link B and Link C)
link A is:
https://abc.mdx.com/p?id={c_val}
link B is:
https://def.xyz.net/c?c_val={id}
Link C is:
https://ajddf.com/adfadfdfa4564
In my database I have a value adgaf7g6adf6gadfg8a86fgs9f6g
Now coming to main point, when someone redirects from link C
I want to pass adgaf7g6adf6gadfg8a86fgs9f6g in Link A
Something like this:
var url_string = window.location.href
var url = new URL(url_string);
var id = url.searchParams.get("id");
window.location.replace("www.redirectaddress.com/p?id="+id); //redirect

javascript regex to get the content of a string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a string
var str="[a54hy 8:45pm],[f57gh 9:20]"
i need to get
[f57gh 9:20pm]
I don't want to use split since the string length can be anything
This worked for me. where id is f57gh
var re='\\['+id + '([a-z0-9: ]+)\\]';
var rematch=RegExp(re,'g');
var mydata=str.match(rematch);
alert(mydata); //[f57gh 9:11am]

javascript - Custom URL Pattern [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Get Values from URL
var acutal_url = HTTP://my_host.com/account/apps/6/dashboard/6;
what i want is
var pattern_url = HTTP://my_host.com/account/apps/<int:app_id>/dashboard/<int:dash_id> ;
I want app_id & dash_id separately from this URL ..
Is it possible using JavaScript?
Try this
var acutal_url = "HTTP://my_host.com/account/apps/6/dashboard/6"
var app_id = acutal_url.substring( acutal_url.indexOf("/apps/") + 6, acutal_url.indexOf("/dashboard/") );
var dash_id = acutal_url.substring( acutal_url.indexOf("/dashboard/") + 11 );
alert(app_id);
alert(dash_id);
You should use regular expressions, but just in case you want a tool to do it for you, try http://txt2re.com/

regular expression in javascript checking for "asdasd<something>asdsada" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how would I check for string
<something> in var string = "some chars <something> somechars"
You can use String.match():
var res = string.match(/<something>/g); // ["<something>"]
If there is no match, the value of res will be null. See example on JSFiddle.

Regex param from url in javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Can you help me please to get some param from an URL.
Url should be the form : http.www.lolilol.com/gallery/Param1/Param2/Param3/
I need to get Param1, Param2 and Param3.
A simple solution :
var params = document.location.pathname.split('/').slice(2);
This gives you the array ["Param1", "Param2", "Param3"]
The regex would be http://www\.lolilol\.com/gallery/(.*)/(.*)/(.*)/ assuming you meant http://www.lolilol.com/gallery/Param1/Param2/Param3/

Categories