Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think I understand the question and that is that you would like to extract "i want(to) extract this text" or something similar from something that might appear like this: this is the text that (i want(to) extract this text) from</p> <p>If so, you might find success with the following regular expression (using $text to define the variable being examined and $txt as the variable being created in the case of a match which is then stored in the array $t[]):</p> <pre><code>if (preg_match('/\(\w+.+\)/', $text, $t)) { $txt = $t[0]; } else { $txt = ""; } echo $desired=substr($txt,1,-1); </code></pre> <p>The RegEx at the root of this is: (\w+.+) and here is the explanation of the code:</p> <ol> <li>Match the character “(” literally «(»</li> <li>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) «+»</li> <li>Match any single character that is not a line break character «.+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»</li> <li>Match the character “)” literally «)»</li> <li>Put the text that is within the parentheses into a new variable $desired. Display the $desired characters by selecting a substring that is reduced by one character on either end, thereby eliminating the bounding parentheses.«echo $desired=substr($txt,1-1)»</li> </ol> <p>Using the above I was able to display: i want(to) extract this text from the variable $text = this is the text that (i want(to) extract this text) from. If desire to pull the "to" from the (to) I would suggest that you run the variable through the regex loop until there are no more ( )'s found in the expression and it returns a null value and concatenate the returned values to form the variable of interest.</p> <p>Best of luck, Steve </p>
    singulars
    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. 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