Regular Expression: Get file extension from string [duplicate] - javascript

This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Get the values from the "GET" parameters (JavaScript) [duplicate]
(63 answers)
Closed 2 years ago.
I have a link (string) which contains a filename. I need to extract the format of the filename but I am unfortunately not able to do that. An example link is given below
www.xyz.com/private/videos/89FDJKDKFgrFTD-MUyKE9Sn/source?file-name=SampleAudio_0.4mb.mp3&token=exp=1591202847~acl=/private/videos/8OJFREFJOIJFREJ-MUyKE9Sn/source*~hmac=aef161514cdfodsjfodsjorjef081b4c849b8c29c6a37339803866badfd4a16
I have tried multiple ways like to look for .(dot) until & but since I am new to this I couldn't make this work. I got the filename through name=([^&]*) but could not get the extension. Is there a way to do this?

You can use this regex:
(?:file-name=.*)(\..+)(?:&)
Also see working example: https://regex101.com/r/CJDXLW/2

Related

I want some specific characters from the link [duplicate]

This question already has answers here:
How to obtain the query string from the current URL with JavaScript?
(19 answers)
How can I get query string values in JavaScript?
(73 answers)
Closed 3 months ago.
The link like this i want only this suyashvashishtha#axl and this address can be dynamic eg: anyaddress0005446556#axl,newaddress#axl i only want this character from pa= to &. Please help me.
upi://pay?pa=suyashvashishtha#axl&pn=Suyash%20Vashishtha&mc=0000&mode=02&purpose=00
I was splitting it but the address is dynamic of different users this method is not working..

Is there a better alternative to slice? [duplicate]

This question already has answers here:
Parse query string in JavaScript [duplicate]
(11 answers)
How can I get query string values in JavaScript?
(73 answers)
Closed 9 months ago.
I'm kind of new to javascript and I was wondering if there was a better alternative to slice. I'm currently using window.location.slice at the moment and it feels like I could be using a better alternative. If you've ever used express.js you might have heard of "req.query.id", something like that in raw javascript would be perfect. Thanks, Alek.

Is it possible to execute the value of an HTML textbox? [duplicate]

This question already has answers here:
How to pass text in a textbox to JavaScript function?
(7 answers)
Closed 2 years ago.
I'm trying to create something that allows people to execute a line of JS. I want to convert the string that people type into a function to execute on the page using the HTML tag
I've looked around and nothing is helping to this.
you can use eval();
example :
eval("console.log('hello')");

Whats the best way to parse a stringified array in javascript? [duplicate]

This question already has answers here:
Safely turning a JSON string into an object
(28 answers)
Closed 3 years ago.
For example: '[test,abc,123]'. How do you turn that into a standard javascript array that can be iterated?
This will work, but really you should fix your input to give you real JSON as is noted in the comments.
console.log(JSON.parse('["test","abc",123]'));

PHP $_GET in plain html/javascript [duplicate]

This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 8 years ago.
I am trying to figure out how to get the parts of a URL I am going to be receiving from a third-party website. The URL I am expecting is something like: index.html?lob=company&ZipCode=22407
All of my pages are coded in .html rather than PHP due to my client's needs/desires, so my question is how can I get the "ZipCode" value.
In PHP this would be super simple, however I cannot do that.
Use Javascript instead.
var value_of_zipcode = "index.html?lob=company&ZipCode=22407".match("ZipCode=([0-9]{5})")[1];
now the value_of_zipcode is 22407

Categories

Resources