[TYPO3-german] OT ... RegEx

Ralf-Rene Schröder ralf.rene at online.de
Mon Apr 10 12:57:48 CEST 2017


Hallo...
vielleicht kann mir jemand der sich mit Regular Expressions auskennt ein
wenig unter die Arme greifen...
Ich möchte bei der Eingabe einer Youtube-Url ODER dann wenn jemand den
Code alleine eingibt, die Eingabe für die DB wandeln in den Code alleine
für den ersten Fall habe ich dies folgende Script, was auch bestens
funktioniert (ist in Formhandler als userFunc eingebunden), aber ein
Code alleine kommt da nicht durch... was muss ich da modifizieren ???

<?php
namespace ImageFormat\IffLayout\User;
use \TYPO3\CMS\Core\Utility\GeneralUtility as GeneralUtility;
class Youtube
{
  var $cObj;
  public function main($content,$conf)
  {
    $conf['url'] = $this->cObj->stdWrap($conf['url'],$conf['url.']);
    $pattern =
     '%^# Match any youtube URL
     (?:https?://)?  # Optional scheme. Either http or https
     (?:www\.)?      # Optional www subdomain
     (?:             # Group host alternatives
       youtu\.be/    # Either youtu.be,
     | youtube\.com  # or youtube.com
       (?:           # Group path alternatives
         /embed/     # Either /embed/
       | /v/         # or /v/
       | .*v=        # or /watch\?v=
       )             # End path alternatives.
     )               # End host alternatives.
     ([\w-]{10,12})  # Allow 10-12 for 11 char youtube id.
     ($|&).*         # if additional parameters are also in query string
after video id.
     $%x'
     ;
     $result = preg_match($pattern, $conf['url'], $matches);
     if (false !== $result)
     {
       return $matches[1];
     }
     return false;
  }
}


-- 
image[FORMAT] - Ralf-René Schröder
http://www.image-format.eu ... Wir geben Ihrem Image das richtige Format


More information about the TYPO3-german mailing list