I have this url string
http://apistaging.yoolk.com/listings/F7B519E8-135C-43D0-A35F-764B582EDC48?domain_name=cambodiastaging.yoolk.com&display=basic
I would like to get only the uuid F7B519E8-135C-43D0-A35F-764B582EDC48 from this url by using regular expression in Javascript. How could I do so? Please give me some suggestions.
Thanks you all.
/((\w{4,12}-?)){5}/.exec(URL)[0]
var url = 'http://apistaging.yoolk.com/listings/F7B519E8-135C-43D0-A35F-764B582EDC48?domain_name=cambodiastaging.yoolk.com&display=basi',
matches = url.match(/listings\/([A-F\d-]+)\?/),
UUID = matches[1];
console.log(UUID); // F7B519E8-135C-43D0-A35F-764B582EDC48
jsFiddle.
I would do it with splits.
var uri = 'http://apistaging.yoolk.com/listings/F7B519E8-135C-43D0-A35F-764B582EDC48?domain_name=cambodiastaging.yoolk.com&display=basic'
uri.split('?')[0].split('/')[4]
Related
I've got a string 'url(data:image/png;base64,iVBORw0K...GgoA)'.
I need to invoke only base64 data from it. In output i'd like to see something like this ['iVBORw0K...GgoA'].
Could anyone help me with creating a correct RegExp expression?
Thanks in advance.
.*base64,(\w+)\)$
If you get group 1 from the regex, you will get the base64 data you want.
You can write a regular expression like this,
var phrase = "url(data:image/png;base64,iVBORw0K...GgoA)";
var myRegexp = /base64,(.*)/;
var match = myRegexp.exec(phrase);
alert(match[1]);
HTH
Given
google.com
How can I get .com and save it to a variable. I was thinking of using regex to split google.com into google and ".com", but I don't know the regex to do this.
It might help to know that I got the hostname from using window.location.hostname
Thank you!
You can split the location by ., and the last value in the array will be the extension. Something like this would work:
var extension=location.hostname.split(".");
extension=extension[extension.length-1];
console.log(extension)
JS Fiddle Example: https://jsfiddle.net/igor_9000/yvy0zrat/
Hope that helps!
You could use a substring and lastIndexof:
var str = window.location.hostname;
var ending = str.substring(str.lastIndexOf(".")+1);
https://jsfiddle.net/06r86q0n/
Mostly the same as the other answer, but neither helps with double domains like ".co.uk"
If you are looking to create a regex statement that will only grab the .com then I would use something like:
/(.com)/ as your Regex statement
so your code would look like something like this:
var regexMatch = /(.com)/; as a regular expression literal
or
var regexMatch = new RegExp(".com"); as constructor function of the RegExp object.
Do not use split, its a bit slower than slice:
var last = location.hostname
var t = last.slice(last.lastIndexOf("."));
console.log(t) // .com, .net etc...
Fiddle: https://jsfiddle.net/1qu0rffb/
I have the following strings
"www.mywebsite.com/alex/bob/a-111/..."
"www.mywebsite.com/alex/bob/a-222/..."
"www.mywebsite.com/alex/bob/a-333/...".
I need to find the a-xxx in each one of them and use it as a different string.
Is there a way to do this?
I tried by using indexOf() but it only works with one character. Any other ideas?
You can use RegExp
var string = "www.mywebsite.com/alex/bob/a-111/...";
var result = string.match(/(a-\d+)/);
console.log(result[0]);
or match all values
var strings = "www.mywebsite.com/alex/bob/a-111/..." +
"www.mywebsite.com/alex/bob/a-222/..." +
"www.mywebsite.com/alex/bob/a-333/...";
var result = strings.match(/a-\d+/g)
console.log(result.join(', '));
Use the following RegEx in conjunction with JS's search() API
/(a)\-\w+/g
Reference for search(): http://www.w3schools.com/js/js_regexp.asp
var reg=/a-\d{3}/;
text.match(reg);
I have one URL which is
https://hpscrmdev.honeywell.com/service_enu_dv2_oui/start.swe?SWECmd=GotoView&SWEView=Home+Page+View+(WCC)&SWERF=1&SWEHo=hpscrmdev.honeywell.com&SWEBU=1
I want this 'service_enu_dv2_oui' part using regex. How can I get that?
Please suggest.
Thanks.
this is without regex but working nicely: http://jsfiddle.net/mKNkF/
var path = "https://hpscrmdev.honeywell.com/service_enu_dv2_oui/start.swe?SWECmd=GotoView&SWEView=Home+Page+View+(WCC)&SWERF=1&SWEHo=hpscrmdev.honeywell.com&SWEBU=1";
var pathArray = path.split( '/' );
alert(pathArray[3]);
If the path only has a single segment as shown in your example, the regex is fairly straight-forward:
/^http(?:s?):\/\/[^\/]+\/([^\/]+)/
Live link with details.
For example:
var str = "https://hpscrmdev.honeywell.com/service_enu_dv2_oui/start.swe?SWECmd=GotoView&SWEView=Home+Page+View+(WCC)&SWERF=1&SWEHo=hpscrmdev.honeywell.com&SWEBU=1";
var match = str.match(/^http(?:s?):\/\/[^\/]+\/([^\/]+)/);
if (match) {
console.log(match[1]); // "service_enu_dv2_oui"
}
Path without host and query you can receive from
window.location.pathname
http://www.w3schools.com/js/js_window_location.asp
No regex required
https?:\/\/[\w\.]+\/(\w+)\/
this regex have one match group
you check this link
i want to extract 34 from this string. How Can i done that ? (i will use javascript)
#project_maincategory=3&project_subcategory=34&project_tags[]=70&project_tags[]=71&created_in=30
var src = "#project_maincategory=3&project_subcategory=34&project_tags[]=70&project_tags[]=71&created_in=30",
match = /project_subcategory=(\d+)/g.exec(src);
alert(match[1]);
Anyways, it looks like a query string so there should be a better way to parse/read that string. See http://blog.falafel.com/Blogs/AdamAnderson/07-12-17/Parse_a_Query_String_in_JavaScript.aspx
.*project_subcategory=(\d*).*