How to get URLinformation after question mark? [duplicate] - javascript

This question already has answers here:
how to get url value after question mark in javascript
(2 answers)
Closed 3 years ago.
I have this simple code:
Subscribe today
when the user press on the a tag it takes him to the page subsc.php?English.
My question is how can i get the information after the ? (which is "English" in this example)?

You can try with Regex Positive Lookbehind /(?<=\?).$*/.
var url = '/subsc.php?English';
var r = url.match(/(?<=\?).*$/)[0];
console.log(r);

Related

Getting Product ID from URL using JavaScript [duplicate]

This question already has answers here:
Last segment of URL with JavaScript
(30 answers)
How do I parse a URL into hostname and path in javascript?
(26 answers)
Closed 1 year ago.
i need to get the product id from an url into a var
https://instrumentall.md/ro/6167922/
can someone help me please?
In JavaScript use window.location.href to get the value of the url. Than process it as a normal string.

Javascript only read certain char from input [duplicate]

This question already has answers here:
How to return part of string before a certain character?
(5 answers)
Closed 6 years ago.
var name = prompt("Enter Name,Barry");
document.write(name);
I want to do exactly this, but only print the first three letters of the 'name'
var name = prompt("Enter Name,Barry").slice(0, 3);
document.write(name)
Try this out it may help.

How to format string in JS? [duplicate]

This question already has answers here:
JavaScript .replace only replaces first Match [duplicate]
(7 answers)
Closed 6 years ago.
I would like to have the result :
28,12,2016
From this string "28/12/2016"
I tried :
("28/12/2016").replace('/',',');
==>"28,12/2016"
I don't know how to delete the second /and the " "
use split and join method
var a="28/12/2016";
var ans=a.split("/").join(",");
console.log(ans);

Behavior of Regex in javascript [duplicate]

This question already has answers here:
escaping question mark in regex javascript
(4 answers)
Closed 6 years ago.
I am new to javascript and have not much idea about regular expressions. Please help me in understanding the following code.
var r = new RegExp("^.*?https://www\\.facebook\\.com/servlet/SignOn.*$","i");
var content = "https://www.facebook.com/servlet/SignOn?msg=You+are+not+authorized+to+vie…r+level+of+authority.&cm_sp=TopNav-_-servlet-_-MMM&goto=MembersMainMenu%3F";
console.log(content.search(r));// It gives me 0
But when I change the regex to
var r = new RegExp("^.*?https://www\\.facebook\\.com/servlet/SignOn?msg=.*$","i");
console.log(content.search(r));// It gives me -1 , why??
n? means n is optional you need n\?

How do I get the last character with jquery [duplicate]

This question already has answers here:
How to get the last character of a string?
(15 answers)
Closed 8 years ago.
I have a string I am trying to get the last character with jquery. How would I do that?
var stringTemp = "fieldNameWithIndex_1";
stringTemp.charAt(stringTemp.length-1);
or
stringTemp.slice(-1);
Use .split():
stringTemp.split('_')[1]

Categories

Resources