ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/usr/bin/python
import re
abc = """
random text
random text
random text
flashvars="flvsource=http://zzz.tvstation.tv/uploads/abcd345mngjrUeoKSDfd.flv&preview_image=http://a.jpg&backgcolor=FFFFFF&autoplay=true&url_logo=http://logo-player.png&logo=top_right&floating_navbar=false&color_nav_bar_top=0x478dc2&color_nav_bar_bottom=0xE7EBEC&ads_background_color=0x00CCFF&ads_border_color=0xCCCCCC&scrubber_position_color=0x6AA1CE&scrubber_load_color=0x888888&scrubber_background_color=0xBBBBBB&volume_bar_color=0xBBBBBB&aspect_ratio=stretch"></embed>' onClick="javascript:document.code.embed.focus();document.code.embed.select(); return false;" />
random text
random text
dsfgdsgdgdgdgdgdfgdgdfretrtsdgdf
"""
flvsource = re.findall('http://zzz.tvstation.tv/uploads/abcd345mngjrUeoKSDfd.flv', abc)
flvsource2 = re.findall('http://zzz.tvstation.tv/uploads/*.flv', abc)
print flvsource
print flvsource2
i need to extract this kind of string:
"http://zzz.tvstation.tv/uploads/abcd345mngjrUeoKSDfd.flv"
with something similar to this:
"http://zzz.tvstation.tv/uploads/*.flv"
I use the "?" and "*" in bash all the time,
but i'm not familiar with the regular expressions
in python or in ruby.
They are pretty much the same. .* means (roughly) "repeat any character any number of times", whereas .{1,20} means repeat any character between one and 20 times.
So, as you have noticed, they both work for you in this particular case.
I would also point out, that had you used HMW's suggested solution on the extra link I provided, this is where you might get tripped up, however, part of writing regular expressions also relies on how well you know the data, ie. will you never have a file name longer than 20 characters??
hmmm ... yes in that case it would work and i am also not familiar with what alterations there might be, ie. there could be another '.flv' file name further along the string.
My point was to show the issue of greediness can sometimes be a limiting factor
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.