Remove Substring in Javascript [duplicate] - javascript

This question already has answers here:
How to remove text from a string?
(16 answers)
Closed 7 years ago.
In JavaScript, I need to find a substring between &J= and Key using regex and remove it from my url which could contain several substrings.
Here is my url:
SID=18608202881669&Act=432&Mode=1&CLk=T&Key58=6003&dotnetdll=TopCoConfigurator.dll&dotnetfunc=CasingSizeSummary&SID=18608202881669&F=&J=CasingSize/CasingSizeSummary.asp&Key58=6003&ccs_casingsizeid=6003
Thanks

You can learn Regular Expression here and code for your problem is:
Here you go:
SID="18608202881669&Act=432&Mode=1&CLk=T&Key58=6003&dotnetdll=TopCoConfigurator.dll&dotnetfunc=CasingSizeSummary&SID=18608202881669&F=&J=CasingSize/CasingSizeSummary.asp&Key58=6003&ccs_casingsizeid=6003";
var re = /&J=(.*?)&Key/;
SID = SID.replace(re, '');
alert(SID);
See Fiddle

Related

How can I split text into a list everytime it finds a character in JS? [duplicate]

This question already has answers here:
How do I split a string, breaking at a particular character?
(17 answers)
Closed 1 year ago.
I am trying to create a code to iterate through a save code, and I think it’ll be something like this :
Username;Password;Points
How can I split the above text into a list like this : [Username, Password, Points] ,everytime it finds a semicolon using Javascript?
Thanks in advance :)
Just use split:
var input = "Username;Password;Points";
var parts = input.split(";");
console.log(parts);

Regex find url with specefic character inside (js) [duplicate]

This question already has answers here:
Regular expression to stop at first match
(9 answers)
Closed 1 year ago.
I have the following text:
Some text
{\"url\": \"https:\/\/www.someurl.com\/200x200\/fsdffsde3e", \"bbb\"} kljkl
{\"url\": \"https:\/\/www.someurl.com\/500x500\/fsdffsde3e", \"bbb\"} kljkl
Some text
I want to extract all the URLs contains 200x200. so for example I need this URL: https:\/\/www.someurl.com\/200x200\/fsdffsde3e
this, will bring the entire row: "https(.*?)200x200(.*)" but I want only the URL.
Have a look: https://regex101.com/r/DDWLDM/1
Thanks
use This exp
"https(.*?)200x200(.*?)"

Add a variable into a regex [duplicate]

This question already has answers here:
How do you use a variable in a regular expression?
(27 answers)
Closed 2 years ago.
I've got a little problem of comprehension with my regex
I just want add a variable inside my regex
I've got this:
static test(Prefix, version: string) {
return "/^" + Prefix + "[0-9]*.[0-9]*.[0-9]*-[0-9]*-(SNAPSHOT)$/.test(version);
}
// I don't understand where to put my last "
thanks for your help
You can build a regexp expression via new RegExp(string)

regex to grab url from string [duplicate]

This question already has answers here:
Regular expression to find URLs within a string
(35 answers)
Closed 7 years ago.
I have this json object
arr[i].text
which returns
check this http://www.newlook.com/shop/womens/dresses/navy-short-sleeve-check-tunic-dress-_320165649
I want to return only the URL with a regex like so:
var urlreg = /(\bhttps?\:\/\/(www)?\.\w+\.\w+(\/[\w\d\-]+)*)/;
match = urlreg.exec(arr[i].text );
but doesn't work, is it something to with it being an object and not a string?
Try: var urlreg = /(https?:\/\/(\w+\.)+\w+(\/[\w\-_]+)+)/\/?
Here is a demo

Replace values between parentheses using Javascript and Regex [duplicate]

This question already has answers here:
How can I replace a string in parentheses using a regex?
(4 answers)
Closed 7 years ago.
I need to replace the text between two parentheses using Regex in Javascript. For example:
var x = "I need to go (now)";
I need to replace 'now' with 'tomorrow'. I tried this, but it didn't work:
x.replace(/\(now)\b/g, 'tomorrow');
"I need to know (now)".replace(/\(now\)/g, 'tomorrow');
You don't need the \b and you need to escape the second ).

Categories