Regular Expression Help - finding string of certain length

I need help with a regular expression.  The following expression identifies strings of 4 bytes or more.  However, it does not seem to work when the string has a special character like "-".  

\w{4,}

For Example;

1234                       -->   Found.
23-44                     --> Not found

How can I get this to work with special characters?
tmajor99Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
[\w-]{4,}

HTH,
Dan
Terry WoodsIT GuruCommented:
The reason for Dan's answer is because the code "\w" matches a single character that is alphabetic, numeric or an underscore. It doesn't match a hyphen character.

The "[\w-]" part of Dan's suggested pattern matches a single character that matches the above description for \w or is a hyphen. You can add more characters between the square brackets if you want other characters to be matched too. Make sure the hyphen is always last in the list or it needs to be prefixed with a backslash character (without the backslash, it indicates a range of characters like 1-5)

[\w^&#-]{4,}

Open in new window


Alternatively, you could just use a different wildcard character such as a period "." which matches any single character (except a newline). Bear in mind it also matches space characters, tab characters, line feed characters etc. There's also the wildcard \S which matches any non-space character.

\S{4,}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tmajor99Author Commented:
n/a
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.