Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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



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

share|improve this question

1 Answer 1

Use this regex:


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)

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

share|improve this answer
Thanks mvp, but when I tested it using this RegEx tester: It returns "period_1_1364871116_438861511.ssa" and not "1364871116_438861511" – Paul M Apr 2 '13 at 6:47
Which language you are using? I have tried my Perl code, and it does work. For regex tests online, I prefer, this link proves that it works for Java for example (see group(1)) – mvp Apr 2 '13 at 6:56
Python and/or .JS, I think. I'm using this in XBMC, if you're familiar with it. I'm not a programmer, so I just need a reg expression that returns just "1364871116_438861511". Thanks for your help bro! – Paul M Apr 2 '13 at 7:04
Use this link and click on Python test: it shows that you should use findAll() or group(1) methods to get what you want. – mvp Apr 2 '13 at 7:07
Edited answer to add Python example – mvp Apr 2 '13 at 7:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.