javascript - Custom URL Pattern [closed] - javascript

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/

Related

How do I check if the value of an input is a number using jQuery [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 4 years ago.
Improve this question
I need to check if the value of the input consists of numbers(0-9). Thanks for helping.
You can use Regular Expressions:
var result = /^[\d]+$/.test(yourInput);
Try to use isNumeric like this:
if($.isNumeric( input ) && parseInt(input)<10 && parseInt(input)>=0){
...
}

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]

Edit a link with javascript prototype [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 8 years ago.
Improve this question
I have an html link like this:
<li id="schedule">
text
</li>
I would like to change the link (href attribute) that this anchor tag points to using javascript.
In my case, I would like to replace the value of the sku in the query string (ie replace '102333' with another number).
try this: http://jsfiddle.net/mig1098/ex6efsce/
var d = document.getElementById('schedule');
var chil = d.children[0];
var data = prompt('your data');
chil.setAttribute('href','/schedule?sku='+data);
alert(chil);
var url = chil.getAttribute('href');
var m = url.replace(/\/schedule\?sku\=/,'');
var r = document.getElementById('resp');
r.value = m;

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.

how to use regular expression to change url in php [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
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

Categories