0
I have a string = "[VIDEO]http://www.youtube.com/watch?v=etye3skwu9w[/Video]"

I am using the following Regex to match VIDEO tags

'/\[VIDEO\](.+?)\[\/VIDEO\]/i'

It works fine if there is no space in [VIDEO] tag. But if there is any space like [ VIDEO ], it will not work.

How can I ignore spaces. I mean if the Tag is like this [ VIDEO ], my REGEX Should Work.

2 Answers 2

3

Add a \s* at the positions where you want to allow whitespace. \s is whitespace, * is any number of repetitions (including zero):

'/\[\s*VIDEO\s*\](.+?)\[\s*\/VIDEO\s*\]/i
Sign up to request clarification or add additional context in comments.

Comments

1

\s matches any whitespace. You could use this:

'/\[\s*VIDEO\s*\](.+?)\[\s*\/\s*VIDEO\s*\]/i'

This allows whitespaces like [ VIDEO ] or [/ VIDEO]. Or, to allow just spaces

'/\[ *VIDEO *\](.+?)\[ *\/ *VIDEO *\]/i'

or one space

'/\[ ?VIDEO ?\](.+?)\[ ?\/ ?VIDEO ?\]/i'

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.