I want to get some URLs of images in Js/HTML:
var a = "http://sub.domain.com/uploads/files/11-11-2011/345301-574-1182-393/2202.jpg";
var b = "http://sub.domain.com/uploads/files/23-11-2011/234552-574-2321-232/asd.png";
Looking for solution that will detect image url. So the output will be:
http://sub.domain.com/uploads/files/11-11-2011/345301-574-1182-393/2202.jpg
http://sub.domain.com/uploads/files/23-11-2011/234552-574-2321-232/asd.png
Thanks!
Based off the information you've given, this should work:
(https?:\/\/.*\.(?:png|jpg))
You can add more extensions by adding |ext after jpg. This will allow for strings with https as well.
Note: You may want to use the case insensitive modifier i to make the capture more inclusive. This would look like:
/(https?:\/\/.*\.(?:png|jpg))/i
A little late to the party, but in trying to do something similar to the OP, I created the following regex, which seems to handle relative links as well as absolute ones:
/([a-z\-_0-9\/\:\.]*\.(jpg|jpeg|png|gif))/i
I created this regex a few days ago:
/^https?:\/\/.*\/.*\.(png|gif|webp|jpeg|jpg)\??.*$/gmi
The ones provided by others in this post work, but will not check for query strings
Example of this regex:
static checkForImage(url){
let regex = /^https?:\/\/.*\/.*\.(png|gif|webp|jpeg|jpg)\??.*$/gmi
let result;
if (url.match(regex)){
result = {
match: url.match(regex)
}
} else {
result = false;
}
return result;
}
checkForImage('https://images-ext-2.discordapp.net/external/yhycJKw8ohsysnU6CBDLQPV4979oQINVmv-fRfu-jL8/%3Fsize%3D2048/https/cdn.discordapp.com/avatars/490535372393021469/a_9e9d0e575eee0221e759257e259681af.gif')
Try this:
/"(http://[^"]*?\.(jpg|png))"/g
$1 is what you want.
A super strict solution to this would be:
/(http[s]*:\/\/)([a-z\-_0-9\/.]+)\.([a-z.]{2,3})\/([a-z0-9\-_\/._~:?#\[\]#!$&'()*+,;=%]*)([a-z0-9]+\.)(jpg|jpeg|png)/i
var regex = /(http[s]?:\/\/.*\.(?:png|jpg|gif|svg|jpeg))/i;
This is the result you want
Related
I have a link that is currently a string. It looks like this:
"<h2>New Test</h2><br><a href='/map/create-new?lat=35.7&lng=-83.55'>Create</a>"
The above works, but when I try to insert variables into the spot where 35.7 and -83.55 are then I end up breaking the link and it doesn't work.
I tried like this:
"<h2>New Launch</h2><br><a href='/map/create-new?lat='+ event.latlng.lat + '&lng=' + event.latlng.lng'>Create</a>"
The variables are event.latlng.lat and event.latlng.lng.
When I try it like this, then the href ends up only being translated to:
map/create-new?lat= so I know that something is wrong with my placement of quotes but I'm just not seeing the issue.
EDIT: just for clarification, it must be a string like I have. I am passing this into a component that I did not make and this is how it works.
You can not add or use variables directly in your markup (html) but you can solve it and get desired results by using javascript (code below):
const customLink = document.getElementById("customLink");
var1 = 35.7;
var2 = -83.55;
customLink.href = "/map/create-new?lat="+var1+"&lng="+var2;
<h2>New Test</h2><br><a id="customLink" href=''>Create</a>
By using the right quotes:
var a = 1;
var b = 2;
var mylink = "http://website.com/page.aspx?list=" + a + "&sublist=" + b;
If you start a string with doublequotes, it can be ended with doublequotes and can contain singlequotes, same goes for the other way around.
This answer was found to this question.
How to insert javascript variables into a URL
best way to use variables within quotes is like this.
<a href=`/map/create-new?lat= ${event.latlng.lat} &lng=${event.latlng.lng}`>
Use variables like this within a string.
<a href=`/map/create-new?lat= ${event.latlng.lat} &lng=${event.latlng.lng}`>
Nothing in the other answers worked for me. I ended up having to install jquery and then used it like this:
var link = jQuery("<a href='#'>Create New</a>").click(function () {
self.onClickCreateNewLaunch(event.latlng.lat, event.latlng.lng);
})[0];
And then just navigated to the page using the function.
What is an appropriate ng-pattern for disallowing
\/:*?"<>|
I've tried so many different approaches.
I did something like this:
const re = new RegExp(/[\/*\\*:*\?*"*<*>*(\|*)]/);
console.log(re.test( 'abcd"ef')); //true
Edit1: Added validation for ' / '
Ended up doing it like so
$scope.fileNamePattern = /^[a-zA-Z0-9;`¬!£$%^&()\-_+={}\[\]##~,.' ]+$/;
I'm trying to find a regex pattern to use with this example to match only the number values after /p/
/store/shop/en/model/brand/Heisman-On/p/15890735"target="">Heisman-on
/store/shop/en/model/brand/Heisman/p/03518616"target="">Heisman
/store/shop/en/model/brand/2tee-Cove3/p/67834675"target="">2tee-Cove3
such as :
15890735
03518616
67834675
This would do the trick:
\/p\/(\d+)
Here is a preview.
Use the first capturegroup.
Here's a way you could get the numbers:
var input = '/store/shop/en/model/brand/Heisman-On/p/15890735"target="">Heisman-on';
var regex = /\/p\/(\d+)/;
var numbers = regex.exec(input)[1];
console.log(numbers); // Output: 15890735
Try the following:
/(?:\/p\/)(\d+)/i
http://regexr.com/3blr5
Your aim would be for the $1 output
Trying to display a set of images from uComponents' MNTP, and can't get a value for the umbracoFile property - in the example below, both umbracoFile and url return empty strings:
foreach (var id in #Model.sliders) {
var media = Model.MediaById(id.InnerText);
if (media != null){
var url = media.umbracoFile;
<p>name = #media.Name</p>
<p>alt = #media.altText</p>
<p>url = #media.umbracoFile</p>
<p>url = #url</p>
}
}
It's getting really really really annoying... I've worked around it in other areas like so, using Model.Media:
<img src="#Model.Media("topRightImage", "umbracoFile")" alt="#Model.Media("topightImage", "altText")" />
But that will only help if with the media picker data type, not mntp. It shouldnt' be that difficult, should it?
I can get the images to load if I rebuild the internal search index, but they're gone again on subsequent refreshes.
I've seen others having similar problems, and would really appreciate a solution...
ta
Nathan
This looks like a bug that was fixed in 4.7.2. See the following codeplex item:
http://umbraco.codeplex.com/workitem/30778
I am working on a regular expression and I need to extract two parts of an expression that is being imported through a flashvars.
//sample data similar to what comes in from the flashvars. Note that the spaces are not after the and symbol, they are there because the html strips it.
var sampleText:String = "height1=60& amp;height2=80& amp;height3=95& amp;height4=75& amp;"
var heightRegExp:RegExp = /height\d/g; //separates out the variables
var matches:Array = sampleText.match(heightRegExp);
Now I need help isolating the values of each variable and putting them in an array...For instance, 60, 80, etc. I know I should be able to write this regular expression, but I just can't get the exec expression right. Any help would be really appreciated!
sorry for not answering the question with regexes directly. I would do this:
var keyvalues:Array = sampleText.split("& amp;");
var firstkey:String = keyvalues[0].split("=")[0];
var firstvalue:String = keyvalues[0].split("=")[1];
Would that help beside the fact, that it is not using RegEx?
Neither the =, & or the ; are special characters, so I think you can use
=|&
in a split call and then the values will be in the odd indices and the height2 style names would be in the even indices.
You can use URLUtil.stringToObject()
Something like this should work:
var s:String = "name=Alex&age=21";
var o:Object = URLUtil.stringToObject(s, "&", true);
However, if you're just getting the flashvars, you should pull them from the loaderInfo of the root.
this.root.loaderInfo.parameters;