0

I thought I'd try and be clever with some JavaScript and use a regexp instead of repeated use of the indexOf method. I failed. Miserably.

I would like to try and match anything (using the test method) in the following order:

predefined string + space + forward slash + one digit number: 3-8 + decimal point

Can someone tell me what the regexp would be?

1 Answer 1

3

Assuming the predefined string is myString:

/myString \/[3-8]\./

Breakdown:

myString    - predefined string (including space)
\/          - Forward slash
[3-8]       - A digit (between 3-8)
\.          - A .

A good resource for regular expressions is http://www.regular-expressions.info/

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

2 Comments

Thanks :) One last question, is [x-y] specifically a digit or just an (entire) integer?
@lpd - neither. It is for a range. You can do [a-z] for all lower case English alphabet, for instance.

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.