-1

I would like to get <IMAGE%> from

< img src= <IMAGE%> width="50" height="35" >

When i use the MatchPattern as "<[^>]*%>" then i get <img src=" <IMAGE%> instead of <IMAGE%>

This is the full string:

< tr>< td>< img src=" <OI_IMAGE%>" width="50" height="35">< /td>< td><NAME%>< /td>< td><EMAIL%>< /td>< td><DELIVERT_DATE%>< /td>< /tr>

I need

<OI_IMAGE%>
<NAME%>
<EMAIL%>
<DELIVERT_DATE%>
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • 2
    There is no need to escape `<` and `>` on SO. Please [edit] your question and show the real data. – simbabque Jan 21 '14 at 22:49
  • 2
    Also: Do not parse HTML with regex. http://stackoverflow.com/a/1732454/1331451 – simbabque Jan 21 '14 at 22:49
  • On SO you accept the answer that solved your problem by clicking the check mark on the left of the answer. That way, others can see how to change it. See [ask]. – simbabque Jan 22 '14 at 08:40

2 Answers2

0

You need to limit the regular expression more. Try /"(<[^>]*%>)/ and use the first capture group. I've assumed your real data looks like this:

<img src="<IMAGE%>" width="50" height="35">

See http://regex101.com/r/wF7eS9 for an explanation.


After your edit: use the character group \w and whitespace and the underscore _ in your char group. Nothing else is allowed between the < %> chars. Add the /g modifier to grab all the instances.

/(<[\w\s_]+?%>)/g

See also updated regex101.com.

simbabque
  • 53,749
  • 8
  • 73
  • 136
  • Thanks for the quick comments I do have other fields which i have mentioned in my question by editing it. If i use your pattern then i cant find others as they don't have " Thanks Again, Rj – user3221281 Jan 21 '14 at 23:13
  • See my edit. For the next question, please give all the details straight away. People are helping you in their spare time and does not feel very rewarding if someone goes back and changes the description of the problem bit by bit. Thanks. – simbabque Jan 21 '14 at 23:53
  • Sorry for the inconvenience – user3221281 Jan 22 '14 at 00:38
0

You just need to change your character class to also negate <:

<[^<>]*%>
Bohemian
  • 412,405
  • 93
  • 575
  • 722