php - Regular expressions - pick up consecutive words that start with a capital letter -
I must select the words that start continuously capitalized in a text (using PHP Then in this lesson - "this is some lesson" it should choose the word "some", but in this lesson - "this is another piece of text" it should be chosen "another piece" that " . I currently have this expression - How do I update it? Is it that I need it? preg_match () )>).
([AZ] [az] +) +
, but it only chooses the word for each capital letter. - [0] = & gt; "another piece" as
, but I currently [0] = & gt; "Other", [1] = & gt; Piece ", [2] = & gt;" off "
)
You can use it:
if (preg_match ('~ [AZ] [az] * (? & Gt; [AZ] [az] *) * ~', $ text, $ m)) {echo $ m [0];}
(? & Gt; [AZ] [az] *) *
optional displays other words.
More flexible Note: If you need to deal with accent words, you can call it (? & Gt; \ s + [AZ] [az] *) *
\ P {LL} and \ p {Lu}
character class:
if (preg_match ('~ \ p {lu} \ p { LL} * (? & Gt; \ S + \ p {Lu} \ p {LL.L *} * ~ ', $ text, $ m) {echo $ m [0]; }
Comments
Post a Comment