Regex - Matching Strings with a Single Character -
i'm new regex. i'm looking expression return results meet following criteria:
- the first word must 3 letters or more
- the last word must 3 characters or more
- if word or words in-between first , last word contains 1 letter, return phrase
- every other word in-between first , last character (apart single letter words) must 3 letters or more
i return phrases like:
'therefore a hurricane shall arrive' , 'however i know i michael smith'
there should space between each word.
so far have:
^([a-za-z]{3,})*$( [a-za-z])*$( [a-za-z]{3,})*$
any appreciated. spacing? i'm using application called 'oracle edq'.
in normal regex world you'd use \b
, word boundary.
^[a-za-z]{3,}(\s+|\b([a-za-z]|[a-za-z]{3,})\b)*\s+[a-za-z]{3,}$ ^^ ^^
see demo
and perhaps, non-capturing groups (as anubhava shows).
from see, there no word boundaries in oracle edq regex syntax (as non-capturing groups). should rely on \s
pattern, matching whitespace.
so, make obligatory, either with
^[a-za-z]{3,}(\s+|\s([a-za-z]|[a-za-z]{3,}))*\s+[a-za-z]{3,}$ ^^
or
^[a-za-z]{3,}(\s+|([a-za-z]|[a-za-z]{3,})\s)*\s*[a-za-z]{3,}$ ^^ ^
Comments
Post a Comment