I have the data below which I am trying to parse out the tittle with each of the following RegEx, Some Entries have a (Year) or other do not. same with the database number. is seem to get different results.


(.*) every character until a "_(" (space open parenthesis) or "-tt" (dash tt) is found



Minions 2-tt2293640
Minions 2 (2012)-tt2293640
Chappie (2015)
Peanuts Movie, The (2015)
Batman Bad Blood (2016)-tt4870838
Ant-Man (2015)-tt0478970
22 Jump Street (2014)-tt2294449
Bean (1997)
Bedtime Stories (2008)
Begin Again (2013)
Beneath the Planet of the Apes (1970)
Best of Me, The (2014)
Beverly Hills Cop (1984)
Beverly Hills Cop II (1987)
Beverly Hills Cop III (1994)
Big Hero 6 (2014)
Big Short, The-tt1596363
Birdman (2014)
Biutiful (2010)
Black Book (2006)
Blackhat (2015)-tt2717822
Black Hawk Down (2001)
Black Mass (2015)-tt1355683
Black Swan (2010)
Blade Runner (1982)-tt0083658
Blended (2014)
Blood Ties (2013)
Body Of Lies (2008)
Bolt (2008)
Born To Be Wild (2011)

Does anyone have a clue as to what I am missing?


1 Answer 1


Using the perl regexp engine (you did not specify what you are using), this can be achieved with:

perl -pe 's/^(.*?)( \(|-tt).*/\1/' < indata.txt

The trick is to make the first .* match non-greedy with .*?, or it will consume the year part for any line that has both a year and the -tt id.

  • Not perl, right now i am just testing testing the expression on the site. the only difference here is the is "?" Quantifier. i think that should the trick. running are test now. thank you for the quick response.
    – user68650
    Commented Apr 10, 2016 at 19:28

You must log in to answer this question.

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