Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should work for your given example. </p> <p>A word of caution though,as others have mentioned allready, Regexes are not the best tool for what you need. Given regex works for your example, nothing more, nothing less. There are lots of SQL constructions imaginable where this regex will <strong>not</strong> make the replacements you need.</p> <pre><code>$result = preg_replace('/(FROM|JOIN|,) ([_\w]*) (AS)/m', '$1 so_$2 $3', $subject); </code></pre> <hr> <pre><code># (FROM|JOIN|,) ([_\w]*) (AS) # # Match the regular expression below and capture its match into backreference number 1 «(FROM|JOIN|,)» # Match either the regular expression below (attempting the next alternative only if this one fails) «FROM» # Match the characters “FROM” literally «FROM» # Or match regular expression number 2 below (attempting the next alternative only if this one fails) «JOIN» # Match the characters “JOIN” literally «JOIN» # Or match regular expression number 3 below (the entire group fails if this one fails to match) «,» # Match the character “,” literally «,» # Match the character “ ” literally « » # Match the regular expression below and capture its match into backreference number 2 «([_\w]*)» # Match a single character present in the list below «[_\w]*» # Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*» # The character “_” «_» # A word character (letters, digits, etc.) «\w» # Match the character “ ” literally « » # Match the regular expression below and capture its match into backreference number 3 «(AS)» # Match the characters “AS” literally «AS» </code></pre>
    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. VO
      singulars
      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