1

I can't figure out how to make a certain regex, even with the help of a regex generator.

I need to get exactly the string between (including spaces): </a>: and &nbsp;.

If nobody wants to get a headache over doing this, I can understand.

11
  • 1
    Could you provide an example? Commented Jan 10, 2013 at 17:03
  • 2
    Can you give an example of input and your expected output. The way you've worded this it doesn't make sense. Also, I like to use regexhero.net when working with regular expressions. Commented Jan 10, 2013 at 17:04
  • I tried to fix the formatting in the question. Commented Jan 10, 2013 at 17:06
  • I'm assuming it's some data ": " <some string and etc. " " somedata They want to get the whole ": " <some string and etc. " " Commented Jan 10, 2013 at 17:07
  • 1
    @MaartenBoogaard: There is no reason to remove it. If you want to improve it, you can edit it Commented Jan 10, 2013 at 17:14

1 Answer 1

1

You would use lookaround to match this: /(?<=<\/a>: ).*(?=&nbsp;)/

However, JavaScript does not support lookbehind, so you are bound to be using matching groups:

var regex = /<\/a>: (.*?)&nbsp;/;
var match = myString.match(regex);
if (match)
    return match[1];
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but how does it return an array? (match[i]?)
Have a look at the docs for the String match method
Alright, regardless, works perfect! Thank you very much for your effort. I can't vote your answer useful because of my low reputation, but you bet that it was extremely useful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.