-2

I want to create a Regular Expression which takes starting and ending point and returns the text between them.

For Example:

<cite>www.weddingsandevents.<b>co.in</b>/album.<b>php</b>?<b>id</b>=2</cite>
<cite>www.nsiccareers.<b>co.in</b>/general_document.<b>php</b>?<b>id</b>=27</cite>
<cite>www.mrpc.<b>co.in</b>/users_article.<b>php</b>?<b>id</b>=3</cite>

The above is in string and i want to get the url between the <cite></cite>

Osama Xäwãñz
  • 437
  • 2
  • 8
  • 21
  • 1
    [Do not](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags#answer-1732454) parse HTML with regex. – Dmitry Sep 12 '17 at 12:05

1 Answers1

1

let testcases = [
'<cite>www.weddingsandevents.<b>co.in</b>/album.<b>php</b>?<b>id</b>=2</cite>',
'<cite>www.nsiccareers.<b>co.in</b>/general_document.<b>php</b>?<b>id</b>=27</cite>',
'<cite>www.mrpc.<b>co.in</b>/users_article.<b>php</b>?<b>id</b>=3</cite>'];

function getMatches(str){
    let result = str.match(/<cite>(.*)<\/cite>/);
    if(result){
        console.log(result[1].replace(/<\/?b>/g, ''));        
        return result[1].replace(/<\/?b>/g, '');
    }
    return null
}

for(let test of testcases){
    getMatches(test);
}
marvel308
  • 10,288
  • 1
  • 21
  • 32