Good day. There is a question. Input data are as follows:

var reg = /([www]*\.+[a-z0-9]+\.+[az]*\S)|(\S+\:\/\/[a-z0-9\:\/_.?=&%+AZ-]*\S)/igm; 

For example text:

3) In EV, next to SDM, there should be an icon when clicking on which the corresponding EV is opened with a new layer http://prntscr.com/cl6rer Icon http://fontawesome.io/icon/arrow-circle-right/ Icon size and color http://prntscr.com/cl6s5h

4) In the activity tape, all URLs should be in the form of links — when clicked, click on a link in a new tab

http://prntscr.com/cr001w

http://prntscr.com/cr02ue

The problem is that line breaks are removed. Did I miss something in the regular expression?

    1 answer 1

    The problem you have is not with a regular expression (although there are problems in it, but they are secondary), but with the fact that you use the jQuery.text() function, which ignores line jQuery.text() decorated with the <br/> tag as a result of the input Regular expression receives text without line breaks.

    In the live example of a regular expression, you can see that it correctly finds the links.
    https://regex101.com/r/54FFNT/1

    In the live test of the jQuery.text() function, you can see that it does not take into account <br/> :

     $( document ).ready( function(){ $( "#result" ).html( $("#source").text() ); }) 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <b>Source</b> <div id="source"> test, <br/> sf sdf <br/> sdf </div> <b>Result</b> <pre id="result"></pre>