Search code examples
phpregextext-extraction

Get all matches between distinct substrings occurring on multiple lines


I have a strange problem with reg expression.

I'm trying to getting out the name of the product in a string like this:

#T55.08 #J60.91 #M1/1 #YT102/0///Tie                      #G
#T55.08 #J60.91 #M1/1 #YT102/0///Foulard                  #G
#T55.08 #J60.91 #M1/1 #YT102/0///Pocket handkerchief      #G

i'm using tx2re (http://txt2re.com) to create the reg expression but seems that if the product name has less then 4 character the reg exp doesn't work...

This is my regex

/(#)(T)(55\\.08)( )(#)(J)(60\\.91)( )(#)(M)(1)(\\/1)( )(#)(YT)(102)(\\/0)(\\/)(\\/)(\\/)((?:[a-z][a-z]+))(.)((?:[a-z][a-z]+))/is

Solution

  • This expression will capture the name of your product:

    /#RT55\.08 #J60\.91 #M1\/1 #YT102\/0\/\/\/(.*)#G/
    

    I assume that #T55.08 #J60.91 #M1/1 #YT102/0/// and #G never change.