Yawning Milk Yawning Milk - 1 year ago 115
jQuery Question

jQuery get substring from string having start and end substrings of substring

So I have string, lets say this one:

The quick brown fox jumps over the lazy dog

And lets say that there could be any jumping animal, not only fox, so the string could be different. And I need to get the part of it, lets say this one

brown fox jumps

I know that my string starts with "brown" and ends with "jumps" so I suppose I need some regex to solve this.

I would also be very thankful if someone would explain the structure of writing regex to me, because so far I don't get it.

Answer Source

Just select the word in between would be easiest one.


Regular expression visualization

RegEx Tester

Or if you like to select the animal as single word too:

/(brown (.*) jumps)/i

Regular expression visualization

RegEx Tester

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download