1

I seem to have a love/hate relationship with RegEx in that I love how incredibly powerful it is, but at the same time, I don't quite understand all of the nuances of it yet.

I've got rather lengthy JSON feed that I need to parse and capture ALL of the matches between two specific strings. I've included a link to the regex101.com example with a few of the JSON results.

regex101.com Example

I'm trying to match every string between each /content/usergenerated and /jcr:content

...

I guess what I should really be trying to match is a string that starts with /content/webAppName/en/home and ends before /jcr:content

The path that I care about will always start with /content/webAppName/en/home

3
  • 2
    Your regex is working, you just need to extract the first match from it, as seen in the Match panel on the right. Commented Jan 28, 2015 at 16:41
  • "I seem to have a love/hate relationship with RegEx": don't worry, this is the only true love. Commented Jan 28, 2015 at 16:46
  • My biggest issue that was identified below was that I wasn't using the global modifier. I feel pretty stupid about that mistake. Doh! Commented Jan 28, 2015 at 18:16

3 Answers 3

1

you have to use "positive look-ahead" that match a sequence of digits if they are followed by something https://regex101.com/r/fU1iD1/4

Sign up to request clarification or add additional context in comments.

1 Comment

Your more compact version works perfectly, thank you!
0

Just wrap the two things you're looking to remove in parenthesis, and then remove them from the output. So...

(\/content\/usergenerated)(.*)(\/jcr\:content)

replaced by

/2

Which is everything in the middle of those two.

edit: Sorry, didn't look at your example :) - there was a deleted answer that said to add the g modifier, which looks like it works.

1 Comment

This works as well, though it returns more than I really need. Mulder90's response is what I should have been doing from the start. Nevertheless, thank you!
0

/content/usergenerated/content/webAppName/en/home([a-zA-Z/-]+)/jcr:content

This should work. It matches 3 out of 4 don't know why it doesn't match one of em. You could use exec() in a loop till it returns null and get hold of the object[1] which contains data for the first and only capture group.

all the best.

PS: I used gmi in options for the regex.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.