Never been to DZone Snippets before?

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

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Extract the filename from a URL

This ECMAScript extracts the filename from a URL. eg. the filename 'index4.svg' would be extracted from the document.URL with the value 'http://rorbuilder.info/r/whiteboardqueue/index4.svg'.
var regexp = /(\w|[-.])+$/
str = document.URL
a = regexp.exec(str)
alert(a[0])

Reference: Regular Expressions: Methods - Doc JavaScript [webreference.com]

Using Regular Expressions to validate a fixed length numerical string.

Using Ruby and Regular Sxpressions, this code successfully validates a string if it contains exactly 3 numbers.

a = '547'
/^\d\d\d$/ ~= a

Using Regular Expressions to validate a numerical string.

Using Ruby and Regular Expressions, this code validates a string for numbers only. If the string variable contains only numbers then 0 will be returned otherwise nil.

a = '134323'
/^[0-9]*$/ =~ a
#result returns 0, indicating success
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS