2

I have a pattern like:

\[[0-9],([0-9]|1[0-4]),[0-9],([0-9]|1[0-4])]

that perfectly matches the strings that are in form of

e.g.

[1,1,1,2]
[5,6,5,7]

I want the string like

[1,1,1,2]kwfkbkkbdobug

be recognized as a false or invalid and not compatible with the pattern, while by using current pattern the string that I mentioned will be recognized as a valid string because it has a [1,1,1,2] string inside regardless of existence of kwfkbkkbdobug.

What would be the best pattern in order to satisfy the need?

1 Answer 1

4

Just make use of the beginning of line anchor and the end of line anchor:

^\[[0-9],([0-9]|1[0-4]),[0-9],([0-9]|1[0-4])]$

^ is the beginning of line anchor which matches only at the beginning of a line.

$ is the end of line anchor which matches only at the end of a line.

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

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.