-2

I'm looking for a regex to get from this:

<%image(20100213-na-de-les-mag-hij-even-blijven.jpg|120|120|)%>

to this:

20100213-na-de-les-mag-hij-even-blijven.jpg

Should be really simple but I'm kinda new to regex and been trying for over an hour now. I think the < and % and | are things that regex uses and I have to escape them?

Thank you!

Jeroen
  • 1
  • Note that this is probably a homework assignment! – Tim Sep 08 '14 at 09:50
  • Probably not homework.. looks more like a scraper. Anyway, it's a trivial regular expression, but "What has been tried? How does it not work as expected?" [There is probably enough information here](http://www.regular-expressions.info/) to able to solve this problem on your own. – user2864740 Sep 08 '14 at 09:51
  • 2
    @user2864740 I guess it is homework because it is Dutch. Translated: He has to stay after class. – GuyT Sep 08 '14 at 09:53
  • Looks like an ok question from a newbie? Why not just replace `` with '' - easier code to write. – Boz Sep 08 '14 at 09:55
  • @GuyT That's presumably the name of the image (to display 120x120) taken/added 2010 or before, not a statement made by the OP. – user2864740 Sep 08 '14 at 09:56
  • If you're new to regex check this out: http://stackoverflow.com/q/22937618/3622940 – Unihedron Sep 08 '14 at 10:17
  • You escape characters with `\\` – pstenstrm Sep 08 '14 at 10:22
  • it also works http://regex101.com/r/iX5xR2/21 – Avinash Raj Sep 08 '14 at 10:35
  • Thank you guys, and indeed I could just replace the It's a custom migration from nucleus to wordpress. Already done with it thanks to your help :) – Jeroen Sep 15 '14 at 09:23

2 Answers2

1

definely this one shall match :

\(([^\|]+)\|

with delimiters :

/\(([^\|]+)\|/

Jack
  • 152
  • 1
  • 8
  • +1, but the last `|\` is not mandatory because you capture every thing that is not a pipe. – Toto Sep 08 '14 at 11:06
0

Try something like this:

<%image\((.*)\|.*\|.*\|\)%>

You have to escape the characters |, ( and ), you will be able to capture the stuff inside the parentheses (.*). (Greedy)

http://regex101.com/r/eY6kM2/1

Or for a more lazy approach:

<%image\(([^\|]*?)\|.*\|.*\|\)%>

http://regex101.com/r/eY6kM2/2

Jonathon
  • 13,610
  • 9
  • 63
  • 84