What could be wrong in this code?

Posted on 2012-08-29
Last Modified: 2012-08-29
Hello Experts,
Please let me know what is wrong with this code.I dont get the output in the console.
var str="";
Question by:dvcphp
    LVL 10

    Expert Comment

    In your regex: /\.[^.]+/

    If i understand correctly, this expression will return a match that "is a period followed by a any one or more characters that is not a period". The result that is returned will be replaced by nothing (the double quotes).

    In "" the match is the first period followed by m. That is where it stops because a period followed by an m followed by a period does not meet the regex criteria.
    LVL 10

    Expert Comment

    Looking closer that the regex:

    /.../ The outer forward slashes says im a regular expression.

    \. A dot is metacharacter outside a character class. In your regex you literally mean a period character. So you escape the dot metacharacter with a slash. So the \. literally means a period.

    [^.] This is a negated character class. This is used to match any character that is not a period. The period inside a [] is a literal period character. It is not a meta character. So you are saying in this regex that you literally want any character that is not a period.

    + The negated character class matches any character. The plus means you require at least one match; and unlimited matches are allowed. So one or more matches that are not a period.
    LVL 10

    Accepted Solution

    I meant to ask, why do you feel it is wrong?

    Author Comment

    Thanks.very good explanation.I appreciate.will give u full points.
    Thanks again.
    LVL 10

    Expert Comment


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now