Solved

PHP  regex(?)  call needed

Posted on 2014-01-21
2
369 Views
Last Modified: 2014-01-22
i have a $string  (max length, say 100 chars) that is (english) text/paragraph that can
contain alpha/numeric/punctuation/linebreaks/hyphens/apostrophe/etc.

i'd like a statement that determines  yes or no   are there  "words" (azAZ09-_')  that exist that are longer than $MaxLength characters  without an intervening  word separator (i.e., non word character).
THe particulars are somewhat flexible for exact definition of "word" and "separator"

is there some sort of regex (or other) PHP call that can evaluate  $String  for  words > $MaxLength

thanks!
0
Comment
Question by:willsherwood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39799099
This seems to work nicely:
if (preg_match("/[\w\-']{".($MaxLength+1)."}/s", $string)) {
  print "A word is too long\n";
} else {
  print "You're all good, bro\n";
}

Open in new window

0
 

Author Closing Comment

by:willsherwood
ID: 39799610
very concise,  MANY THANKS!!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question