Hi everyone,
I am currently working on a project where I need to validate user input for directions. The directions can be either "North", "South", "East", or "West". I am looking for a regular expression in PHP that can match any of these directions.
I have tried using the pattern `/[North|South|East|West]/`, but it seems to match any character within the square brackets rather than the whole word. For example, it would also match "N", "o", "r", "t", etc.
Can anyone please suggest a regular expression that can accurately match only the complete words "North", "South", "East", or "West" in PHP?
Any help or guidance would be greatly appreciated!
Thanks in advance.

Hey there,
I had a similar requirement to validate directions in one of my PHP projects, and I found a solution that might work for you. You can try using the word boundaries `\b` in your regular expression pattern.
So, instead of `/[North|South|East|West]/`, you can modify it to `/\b(North|South|East|West)\b/`. This will ensure that the regular expression only matches the complete words "North", "South", "East", or "West" and not any individual characters within those words.
I tested this approach in my project, and it worked perfectly to validate the directions. Give it a try, and let me know if it helps in your case.
Good luck with your project!