views:

60

answers:

3

How would I go about removing numbers and a space from the start of a string?

For example, from '13 Adam Court, Cannock' remove '13 '.

+5  A: 
str.replace(/^\d+\s+/, '');
BoltClock
Nice rep hike. Last time I checked I was catching up to you, but you got like +1000 rep in the past few days. BTW +1 for an answer giving the OP exactly what they want.
NullUserException
@NullUserException: LOL I knew you were gonna say that! Yup, you were even well ahead of me just last month ;) *Edit:* looks like your vote's capped my rep for the day!
BoltClock
Yeah, I've been busy. School just started. It's my last year in college and I want make the most of it. But before that, I want to get to 10k LOL
NullUserException
@NullUserException: my exams are starting, and since they happen to be programming-related I figured SO would be a nice place to practice and revise — besides my notes. 10k by this week should be easy enough for me.
BoltClock
+6  A: 

Search for

/^[\s\d]+/

Replace with the empty string. Eg:

str = str.replace(/^[\s\d]+/, '');

This will remove digits and spaces in any order from the beginning of the string. For something that removes only a number followed by spaces, see BoltClock's answer.

NullUserException
+1 for fuzzy matching with character classes.
BoltClock
A: 
var text =  '13 Adam Court, Cannock';
var match = /\d+\s/.exec(text)[0];
text.replace(match,"");
João Gala Louros