A
A
Arthur Koch2012-03-16 16:11:29
JavaScript
Arthur Koch, 2012-03-16 16:11:29

js regex

There is a format line #xxxxyyyyyyy where x is a lowercase Latin letter (there are strictly 4 of them), and y is a number from 0 to 9 (it can be arbitrarily)
Task: carve a lattice, put letters in the first variable, numbers in the second. I'm not good at regulars, please help.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
avalak, 2012-03-16
@dudeonthehorse

In fact, there is no need for regularity.

var source = "#abcd123123123123123123123123";
var part1 = source.substr(1, 4);
var part2 = source.substr(5, source.length - 5);

S
Stdit, 2012-03-16
@Stdit

.match(/^#([az]{4})(\d+)$/)

K
Keyten, 2012-03-16
@Keyten

var text = '#abcd123123123123123123123123';
var mtch = text.match(/^#([a-z]{4})([0-9]*)$/);
mtch[1]; // буквы
mtch[2]; // цифры

A
anmipo, 2012-03-16
@anmipo

jsbin.com/acuyig/edit

B
Bick, 2012-03-16
@Bick

In general, RegexBuddy always helps when compiling regular expressions, up to not very sane instances a couple of hundred characters long ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question