0

So I'm doing this php puzzle/challenge and the task is to find a string that matches this format:

/^[\w][-.]+([A-B])[^a-z]{3}\.[0-9]{2,4}$/

But I can´t find any documentation what exactly this part means:

[-.]+

The other parts I interpreted hopefully correctly as the following:

/^[\w]

Any word character

[^a-z]{3}

Not a-z 3times e.g. ABC should be accepted

\.[0-9]{2,4}$

It has to end with a number from 0-9 repeated 2 to 4 times.

2 Answers 2

1

a.A123.12 or a-.-.-A123.12 are matched.

Explanation:

/^[\w][-.]+([A-B])[^a-z]{3}\.[0-9]{2,4}$/ matches from beginning to end:

Qty | Characters
----------------------------------------
1   | word character
1+  | "-" or "."
1   | "A" or "B"
3   | all characters apart from a-z
1   | "."
2-4 | figures 0-9
Sign up to request clarification or add additional context in comments.

Comments

1

[-.] means match either a literal - or a literal ., and the + means match one or more of those, so [-.]+ means a string containing any number (but at least one) of -s and .s and nothing else.

Your interpretation of the other pieces is mostly correct, with these notes:

  1. The ^ and $ at the beginning and end mean that you can't have anything in the string before or after what the rest of the regex matches.
  2. There needs to be a literal dot before the ending numbers that you mention.

Note that in the future, you can use regex tester sites like https://regex101.com/ to see exactly what any regex or piece of regex does.

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.