RegEx to return string between 2 specific characters

regex

Can you please advise on how to return a string between 2 specific characters?

Example

http://sds.01/create/http/capital/870745800/create/period_1_1364871116_438861511.ssa

I want to return : 1364871116_438861511, which is between "period_1_" AND ".ssa"

Best Answer

Use this regex:

period_1_(.*)\.ssa

For example, in Perl you would extract it like this:

my ($substr) = ($string =~ /period_1_(.*)\.ssa/);

For Python, use this code:

m = re.match(r"period_1_(.*)\.ssa", my_long_string)
print m.group(1)

Last print will print string you are looking for (if there is a match).

Related Question