#1
  1. No Profile Picture
    Demonic Swordsman DGQB
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Apr 2003
    Posts
    1,043
    Rep Power
    83

    question: javascript/regular expression/reading and writing files


    I am writing a parsing script, which can be done in any language, & I chose javascript b/c I have some basic experience. If some other language, such as Perl, can do this better, please let me know. In a nutshell, I have a text file with phrases to parse out, which are surrounded by delimiters. There is one problem:

    1. the text file contains key characters such as " and \

    Can I assign a variable to this file, even though it contains reserved characters? If this poses a problem, I was thinking about writing a function to go through the text file, and when it catches a reserved character, [namely " and \] then it adds escape characters to it. So if it finds j = "5", it will change it into j = \"5\". So something like:

    Code:
    function addEscapeChars
    {
       //pseudo code
       //goes through the entire text file
    
       if a character == "\""
       {
           add escape character "\" in front;
       }
       if a character == "\"
       {
           add escape characters "\\" in front;
       }
    
    }
    I have written some more pseudo code . Please help with the actual code.

    Code:
    var pattern = [some regular expression]  //needs actual code
    var file = [statement to assign this variable to a file, or something like this] //needs actual code
    parsedTxt = pattern.exec(file); //runs the pattern against the original file
    document.write(parsedTxt); //prints the parsed text
    Last edited by vb.net; June 2nd, 2003 at 04:43 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    JavaScript can't do file input/output, so right off the bat you're not going to get anywhere. That's assuming I interpreted you correctly, that you nead to read and write files to disk. If so, Perl is probably the most powerful language to use, and is usually the defacto standard for doing simple stuff like that.

IMN logo majestic logo threadwatch logo seochat tools logo