Extract the filename from a URL
var regexp = /(\w|[-.])+$/ str = document.URL a = regexp.exec(str) alert(a[0])
Reference: Regular Expressions: Methods - Doc JavaScript [webreference.com]
11330 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
var regexp = /(\w|[-.])+$/ str = document.URL a = regexp.exec(str) alert(a[0])
>dir /B /S | perl -wlne"/([^ ]+)\.htm$/i&&rename$1.'.htm',$1.'.html'"
>find | grep htm | perl -wlne'/([^ ]+)\.htm$/i&&rename$1.".htm",$1.".html"'
class Fixnum def prime? ('1' * self) !~ /^1?$|^(11+?)\1+$/ end end
Regexp.new(array.collect{|string| Regexp.escape(string)}.join("|"))
#!/usr/bin/env python import re import sys mySplit = re.compile (r',', flags=re.MULTILINE) mailadress = re.compile (r'\<.\D*.\D+@\D+.[.]\D+.\>', flags=re.MULTILINE) for i in mySplit.split ("Weng Feng <weng.feng@telia.se>, Erik Andersson <kirean@gmail.com>, Ake Kong <kong@\ goek.se>"): k = mailadress.search(i.strip()) if k: print k.group().lstrip("<").rstrip(">")
class String def chunk_string(average_segment_size = 40, sclice_on = /\s+/) out = [] slices_estimate = self.size.divmod(average_segment_size) slice_count = (slices_estimate[1] > 0 ? slices_estimate[0] + 1 : slices_estimate[0]) slice_guess = self.size / slice_count previous_slice_location = 0 (1..slice_count - 1).each do |i| slice_location = self.nearest_split(slice_guess * i, sclice_on) out << self.slice(previous_slice_location..slice_location) previous_slice_location = slice_location + 1 end out << self.slice(previous_slice_location..self.size) out end def nearest_split(slice_start, slice_on) left_scan_location = (self.slice(0..slice_start).rindex(slice_on)).to_i right_scan_location = (self.slice((slice_start+1)..self.size).index(slice_on)).to_i + slice_start ((slice_start - left_scan_location) < (right_scan_location - slice_start) ? left_scan_location : right_scan_location) end end
/(.*\.)(.*$)/.match(File.basename(file_name))[2]
function makeLinks($sourceText) { $destText = preg_replace( "/([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})/", '<a href="mailto:\\0">\\0</a>',$sourceText); $destText = preg_replace_callback('/\bhttp[^\s]+/',create_function('$matches', 'return "<a href=\"$matches[0]\">" . preg_replace("#(\.|/)#", "­$1", $matches[0]) . "</a>";'),$destText); return $destText; }
function isUrl(s) { var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/ return regexp.test(s); }