0

I'm sure this is really simple but I haven't been able to create one that works.

I need a regular expression to extract a one or two digit number 1-13 from a string such as "(11)" or "(3)"

Thanks :)

1

2 Answers 2

3
result = subject.match(/\b(?:1[0-3]|0?[1-9])\b/);

will match a two digit number between 1 and 13, wherever it may be (as long as it's not part of a longer number or within a word).

If you want to hard-code the parentheses, it's

result = subject.match(/\((?:1[0-3]|0?[1-9])\)/);

and if you want to find more than one match in a single string, use the g modifier (after the last slash).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I am using the first one.
1

var theNumber = parseInt(theString.replace(/\(([1-9]|1[1-3])\)/, '$1'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.