开发者

Regular Expression (Hyphens, Underscores, and Periods)

I need a regular expression that will be able to detect:

https://s-dPICS-sac323.domain.com/a12_hyJ_k87ds_x.jpg

Will this code do it:

var x = /(https:\/\/[A-Za-z0-9.-]*PICS[A-Za-z0-9._\/]*\.jpg)/g;

Will this be able to detect something along the lines of:

Note: everything except https://, PICS, domain.com, and .jpg are random alpha-numeric characters for this example. I'm trying to detect all of th开发者_JS百科e rest of the characters.

Thanks for your help!


Try this instead:

/https:\/\/[a-z0-9.-]*photos[\w.\/-]*\.jpg/i

Demo: http://rubular.com/r/flmf92C3T2


Don't escape normal slashes, they aren't magic characters.

    /https:\/\/[\w.-]+PICS[\w.\/-]+\.domain\.com/[\w.\/-]+\.jpg/


/(https:\/\/[A-z0-9.-]*PICS[A-z0-9.-]*domain\.com[A-z0-9.-/_]*\.jpg)/ will match "https://s-dPICS-sac323.domain.com/a12_hyJ_k87ds_x.jpg".

And /(https:\/\/[A-z0-9.-]*photos[A-z0-9/.-]*\.jpg)/ will match "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc3/12868_695309462154_5301742_40115272_5760577_n.jpg" with https://, photos, and .jpg being constant.

Is there something more you need out of it? Give it a try at regexpal.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜