fork(1) download
  1. String getYouTubeUrl(String content) {
  2. RegExp regExp = RegExp(
  3. r'((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?'
  4. );
  5. String matches = regExp.stringMatch(content);
  6. if (matches == null) {
  7. return ''; // Always returns here while the video URL is in the content paramter
  8. }
  9. final String youTubeUrl = matches;
  10. return youTubeUrl;
  11. }
  12.  
  13.  
  14.  
  15. void main() {
  16.  
  17. print(getYouTubeUrl(
  18. """ <figure
  19. class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio">
  20. <div class="wp-block-embed__wrapper">
  21. <iframe
  22. title="| Title here |"
  23. width="1170"
  24. height="878"
  25. src="https://w...content-available-to-author-only...e.com/embed/OWGnQ61kLzw?feature=oembed" // <-- I want to get this link frameborder="0"
  26. allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
  27. allowfullscreen
  28. ></iframe>
  29. </div>
  30. </figure>
  31. """
  32. ));
  33. }
  34.  
Success #stdin #stdout 1s 122212KB
stdin
Standard input is empty
stdout
https://w...content-available-to-author-only...e.com/embed/OWGnQ61kLzw?feature=oembed"