Why doesn't the tenth point symbol work regularly?



  • Why doesn't the tenth point symbol work regularly? . - (tenth point) corresponds to any symbol other than the portability of the line.

        var reg2 = /([\s.]+$)/ig;
        var match2;
    
    while (match2 = reg2.exec("drgdrgdgdrgdgr       ыуаыуаыуа
    

    ыуаыаыа")) {
    console.log(match2[1]);
    }

    The result is that there is no symbol according to the decimal point.

    It is necessary to find the line according to . and symbol \sThat's how it is. /([,\w!\s]+)$/ig

    Just like that... /([.\s]+)$/ig - but ten symbol . not working at [].


    That's the expression that works-- that's a decimal point. Why would I list all the symbols between the [] that support the point?


    1. This violin demonstrates the expression that I (this is supposed to work)

    /([,А-Яа-я\w!\s]+)$/ig

    This is a working example. http://jsfiddle.net/ezgefzjy/2

    https://imgur.com/gDdH9s9

            var reg2 = /([,А-Яа-я\w!\s]+)$/ig;
    var match2;

        while (match2 = reg2.exec("Тест А сейчас будет перенос на новую строку
    

    это наш текст на новой строке")) {
    console.log(match2[1]);
    }

    2. Option (this is not true) -

    /(\s+|.+)$/ig

    https://jsfiddle.net/dfeooyak/

    https://imgur.com/4brhHRM

            var reg2 = /(\s+|.+)$/ig;
    var match2;

        while (match2 = reg2.exec("Тест А сейчас будет перенос на новую строку
    

    это наш текст на новой строке")) {
    console.log(match2[1]);
    }

    3. Option (this is not true) -

    /(\s+|.+)$/igm

    https://imgur.com/SNvPWhW

            var reg2 = /(\s+|.+)$/igm;
    var match2;

        while (match2 = reg2.exec("Тест А сейчас будет перенос на новую строку
    

    это наш текст на новой строке")) {
    console.log(match2[1]);
    }



  • Inside [] the point is not regarded as a special symbol but as a symbol of the point, so the regular expression is searching for the text of the point and submarine symbols.

    A decision may be waived []in favour | for example

    var reg2 = /(\s+|.+)$/ig;
    var match2;
    

    while (match2 = reg2.exec("rgrgr rgrgrg rgrgrgrgrg")) {
    console.log(match2[1]);
    }

    Upd. for an added example, the limitation of the line may be removed $

    var $text_area = $('textarea'),
    htmlParser,
    chat_description2_preview = $('.chat_description2-preview');

    function check() {
    chat_description2_preview.text("");
    tested($text_area.val());
    }

    $text_area.on('input propertychange', check);

    function tested(text) {
    var reg2 = /(.+|\s+)/ig;
    var match2;

    while (match2 = reg2.exec(text)) {
    if (match2[1] != undefined) { //ссылка в конце строки или просто строка без изображения
    chat_description2_preview.append(match2[1]);
    console.log(match2[1]);
    }
    }
    }

    check();

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div>Пример номер 1</div>
    <textarea rows="10" cols="45" name="text">
    Тест А сейчас будет перенос на новую строку
    это наш текст на новой строке
    и еще раз
    и еще
    и опять
    и снова
    </textarea>
    <span></span>

    <div style="white-space: pre;" id="con_pred" class='chat_description2-preview'></div>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2