Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Help with js error please NEWBIE

    Hi. I can't sort out what's wrong with my code. If I uncomment the two lines below it doesn't work and for the life of me I can't see why it shouldn't? I am using this as a js file with a Content Editor Web part on SharePoint 2010. thanks -dave

    [CODE]
    <SCR IHAVE THIS OK ON SITE IPT>

    var formLink2 = (location.href);

    var re2 = new RegExp(".*RootFolder=");

    var myRelatives = formLink2.replace(re2, "");

    //var re1 = new RegExp(“&GroupString.*TRUE”);

    //var myRelatives2 = myRelatives.replace(re1, "");

    alert(myRelatives2);


    </SCR IHAVE THIS OK ON SITE IPT>

    [CODE]

  • #2
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    more info

    an example string I am trying to evaluate (as the location.href) would have this string in it:

    "ASDFASDFRootFolder=ASDFASDF&GroupString2452345gTRUE"

  • #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    If I uncomment the two lines below it doesn't work and for the life of me I can't see why it shouldn't?
    The error console would do that for you.

    Quote Originally Posted by david.rose View Post
    Code:
    //var re1 = new RegExp(&GroupString.*TRUE);
    You must use normal quotes not word-processing characters. For programming, always use a text editor or at worst a word processor in text ( ascii ) mode..

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,032
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Also, it's a good idea when using .* followed by something to use a ? after the .* to turn it into a "non greedy" match. Shouldn't matter in this case, but it's a good habit to get into.

    Code:
    var re1 = new RegExp("&GroupString.*?TRUE");
    But why create regexps as strings if they are constants, in any case? Why not simply
    Code:
    var re1 = /&GroupString.*?TRUE/;
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •