Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have been thinking about this question for a couple hours and although I am somewhat of a novice, I believe I have a way that extracts the mentions and the alerts and stores them into two unidimensional arrays. </p> <pre><code> &lt;?php //a variable ($string) that I thought might look like what you are describing $string='@steve how are you? @tom nice to hear from you. So happy that you joined @joe, cool! @mike sweeet!'; //regex to pull out the mentions and the messages preg_match_all('/@(\w+)|\s+([(\w+)\s|.|,|!|?]+)/', $string, $result, PREG_PATTERN_ORDER); for ($i = 0; $i &lt; count($result[0]); $i++) { $mention[$i]= $result[1][$i]; $message[$i]= $result[2][$i]; } //test to make sure that all mentions are stored for ($j = 0; $j&lt; $i; $j++){ echo $mention[$j],'&lt;br/&gt;'; } //test to make sure that all messages are stored for ($k = 0; $k&lt; $j; $k++){ echo $message[$k],'&lt;br/&gt;'; } ?&gt; </code></pre> <p>The explanation, as provided by Regex Buddy), of the regex that I used: @(\w+)|\s+([(\w+)\s|.|,|!|?]+):</p> <pre><code>Match either the regular expression below (attempting the next alternative only if this one fails) «@(\w+)» Match the character “@” literally «@» Match the regular expression below and capture its match into backreference number 1 «(\w+)» Match a single character that is a “word character” (letters, digits, and underscores) «\w+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» Or match regular expression number 2 below (the entire match attempt fails if this one fails to match) «\s([(\w+)\s|\.|,|!|?]+)» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» Match the regular expression below and capture its match into backreference number 2 «([(\w+)\s|\.|,|!|?]+)» Match a single character present in the list below «[(\w+)\s|\.|,|!|?]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» The character “(” «(» A word character (letters, digits, and underscores) «\w» One of the characters “+)” «+)» A whitespace character (spaces, tabs, and line breaks) «\s» The character “|” «|» A . character «\.» One of the characters “|,!?” «|,|!|?» </code></pre> <p>This will even return words in messages that are off-set by parentheses (e.g. (hello)). You should be able to perform any operation you describe using the variables defined in the arrays. If this is not correct, or you are unable, let me know and I will see what I can come up with. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload