Find a string in a string [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How would I write an if statement that alerts when the var MyString is not in the var URL?
var URL = "http://test.mysite.com/about/";
var MyString = "mysite.com";

if (URL.indexOf(MyString) === -1) {
alert('Not found!');
}

if(URL.indexOf(MyString) == -1) alert("Not found");

Related

How to get the array of strings that is in between curly braces inside source string in JavaScript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Suppose the JavaScript variable is:
var sourceString="stack {overflow} is the best {place} to clear {technical} doubts";
Output javascript string array should contain: overflow,place,technical
or {overflow},{place},{technical}
I am fine with both the results.
You could use regex to accomplish this:
sourceString.match(/{.*?}/g)
var getMatchingGroups = function(s) {
var r=/\{(.*?)\}/g, a=[], m;
while (m = r.exec(s)) {
a.push(m[1]);
}
return a;
};
getMatchingGroups(sourceString) // ["overflow", "place", "technical"]

how to get the integer value from javascript variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following function
function answerQ(value) {
var newVal = value;
alert(newVal);
}
and the input button
<input type="button" onClick="answerQ(this.value)" value="Answer Q2">
how can I get just the integer "2" out of this??
Remove anything that isn't a number
function answerQ(value) {
var newVal = +value.replace(/\D/g,'');
alert(newVal);
}

How can I convert this coffeescript to js/jquery? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
text = child.html()
text = text.replace /(#include(\s*<.*>)?)/gi, '<span>$1</span>'
text = text.replace /(main\(.*\))/gi, '<span>$1</span>'
child.html text
http://jsfiddle.net/dcro/XKHC8/
This is an answer from my question: Wrapping strings with a span I dont know how to use coffeescript and the one who answer looks unavailable.
From js2coffee.org
var text;
text = text.replace(/(#include(\s*<.*>)?)/gi, '<span>$1</span>');
text = text.replace(/(main\(.*\))/gi, '<span>$1</span>');
child.html(text);

check if url is a root url [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm looking for a regex to test if a url is a root url:
http://site.org TRUE
http://www.example.com TRUE
...
http://www.example.com/dir FALSE
http://www.example.com/image.jpg FALSE
http://www.example.com/dir/file.doc FALSE
Try below regex will do the work
/^https?\:\/\/[^\/]+\/?$/
I tested like this:
var URL = "http://jsfiddle.net/";
var check =/^https?\:\/\/[^\/]+\/?$/.test(URL);
alert(check);
JSFiddle
try this:
var str='url...';
if(str.indexOf("/")<str.indexOf(".")&&(str.indexOf("http://")>-1))
return true;
else
return fals;
Try out with this regular expression
(?\w+)://(?[\w#][\w.:#]+)/?[\w.?=%&=-#/$,]*

if statement incorrect [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to have the variable estimatedVal replaced with avgList if estimatedVal is empty. Something is wrong with my code because with the code below nothing happens. If I remove the if statement everything else works:
$('#estimatedVal').html($(context).find('ul.estimates a:eq(1)').text()
+ ' - ' + $(context).find('ul.estimates a:eq(0)').text());
if(estimatedVal == ' - '") {
$('#estimatedVal').html(avgList);
} else {
$('#estimatedVal').html(estimatedVal);
}
What do I need to do to be able to use the if statement?
You've got a "lonely double quote," use an IDE/Code Editor and quit using Notepad :P
if(estimatedVal == ' - ') {
$('#estimatedVal').html(avgList);
} else {
$('#estimatedVal').html(estimatedVal);
}
You've got a stray double quote in your if.

Categories

Resources