Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"

share|improve this question

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).

share|improve this answer
    
Thanks mvp, but when I tested it using this RegEx tester: digitalcoding.com/tools/regex-tester.html 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 RegexPlanet.com, 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: fiddle.re/e2be6 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .