Jesica Arroyo Salvador
Jesica Arroyo Salvador

Reputation: 143

Grab mp3 url with REGEX

I have a Drupal module to replace a text in this way:

Text to find:
Replace with:

I need to leave just the URL of the mp3. I thought something like:

Text to find: (previous text) (mp3 url) (subsequent text)
Replace with: /2

I found this for the URL of the mp3:

(((http://www)|(http://)|(www))[-a-zA-Z0-9@:%_\+.~#?&//=]+)\.(mp3|MP3)

But I don't know what to use to match the entire text before and after.

(The module is "Feeds Tamper")

Upvotes: 2

Views: 1561

Answers (1)

Vince
Vince

Reputation: 1527

Your regex for mp3 is a bit too complicated.

/(http://)?(www)?[-a-zA-Z0-9@:%_\+.~#?\/=]+\.mp3/i

is a bit easier and shorter.

To match some text before and after that, you can use .*. That matches everything 0 or more times.

Upvotes: 1

Related Questions