RegEx not matching node.js output

Posted on
  • Hello everybody,

    I am trying to match the second string between quotes and while it works fine on node.js it fails on espruino v1.99.

    With the resources available on espruino, how else would you do it?

    espruino 1.99:
    >/\w+\.\w+/g.exec("form-data; name=\"file\"; filename=\"file.txt\"")[0]
    ="me=\"file.txt"
    
    node.js:
    /\w+\.\w+/g.exec("form-data; name=\"file\"; filename=\"file.txt\"")[0]
    => 'file.txt'
    

    v2.01 is broken too.

    Thank you.

  • Looks like there's a bug in how the index of the match is calculated - however if you make it a group then you can extract that group and you're sorted.

    /(\w+\.\w+)/g.exec("form-data; name=\"file\"; filename=\"file.txt\"")[1]
    
  • It's now fixed, so the latest builds will work better

  • Thank you.

    I am not good at regular expressions. A better solution would be to look for the content between quotes after 'filename=' (to also get filenames without extension), but at least we spotted a small bug.

  • Ok, in that case I'd suggest:

    /filename="([^"]+)"/g.exec("form-data; name=\"file\"; filename=\"file.txt\"")[1]

    Which matches filename="..." and returns what's inside the quotes

  • Hello everyone,
    It seems that the quantifiers '?' and '{}' don't work'

    /2?\d/.exec("24") // return null rather than 24
    

    Are they implemented ?

    Thank you.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

RegEx not matching node.js output

Posted by Avatar for barbiani @barbiani

Actions