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 preg_match () )>).

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 - ([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 ")

How do I update it? Is it that I need it?

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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -