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 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2013
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation SyntaxError: Unexpected token <

    Code:
     
    var Regex = \<span class\="robux " data-se="item-privatesale-price"\>([\d,]+<\/span\>
    This is a small snippet of my code, it is supposed to search through the page source of a web page which I have given it with
    Code:
    $.get(websitelink, function(data){
    var Regex = \<span class\="robux " data-se="item-privatesale-price"\>([\d,]+<\/span\>
    When I run this code it returns the error in the title. Am I perhaps escaping the < wrong? I know it is this < because if I delete it it says the exact same for the = sign.

    What am I doing wrong?

    I want it to get the price of this thing with ([\d,]+ and then set that with data.match, so that's why I am doing this.

    Thanks!

  • #2
    New Coder
    Join Date
    Oct 2013
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    For a bit more information here is another part of the code that's not working with a different error.

    Code:
    var hatId = 124472052
    var hatLink = "http://www.roblox.com/x-item?id=" + hatId
    $.get(hatLink, function(data){
    var Regex = "privatesale-price\"\>"+ ([\d]) +"\<span\>"
    The error I am getting is

    SyntaxError: Unexpected token ILLEGAL

    Which character is illegal? Thanks!

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    var Regex = \<span class\="robux " data-se="item-privatesale-price"\>([\d,]+<\/span\>

    is completely invalid.

    Only numbers can be assigned to a variable without wrapping the content to identify its type - [ ] for an array, { } for an object. / / for a regular expression, " " or ' ' for a text string.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    I suggest you read about regular expressions before using them. They must be enclosed in forward slashes. But even though I don’t know what you’re actually trying to achieve, I think the approach is wrong. Read up on DOM traversal and how to retreive elements by type and attributes (e. g. getElementsByClassNamehttp://davidwalsh.name/javascript-attributes).

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Quote Originally Posted by Tomstery View Post
    Code:
     
    var Regex = \<span class\="robux " data-se="item-privatesale-price"\>([\d,]+<\/span\>
    Your regex should be something more like var Regex = /<span class="robux" data-se="item-privatesale-price">\([\d,]+<\/span>/;. That'll match things like <span class="robux" data-se="item-privatesale-price">(1234,1234,1234,,,,,,</span>.

    Of course, if you just want the element, it'd be easier to use something like document.querySelector("span.robux[data-se=\"item-privatesale-price\"]");. Or document.querySelector("span.robux[data-se=\"item-privatesale-price\"]").textContent; for the content. Or document.getElementsByClassName("robux").item(itemIndex).textContent if you know the element's index and want better performance.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

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