JS RegularExpression for MAC file path

Discussion in 'Mac Programming' started by vphope, Jan 9, 2008.

  1. vphope macrumors newbie

    Joined:
    Jan 9, 2008
    #1
    Hi

    I am looking for a javascript regular expression to validate MAC file path

    Example : path/to/filename.txt

    Thanks
    V
     
  2. numero macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #2
    This is the closest I found for a spec, but the page I need to see is gone.

    http://developer.apple.com/technotes/tn/tn1150.html#CanonicalDecomposition

    It would be nice to be able to find this page.
    http://developer.apple.com/technotes/tn/tn1150table.html

    The Unicode Decomposition table contains a list of characters that are illegal as part of an HFS Plus string, and the equivalent character(s) that must be used instead. Any character appearing in a column titled "Illegal", must be replaced by the character(s) in the column immediately to the right (titled "Replace With").​

    If you come up with the list of illegal characters I can help you with the regex. The easy illegal character is ":", but this missing link promises some others.

    -numero
     
  3. vphope thread starter macrumors newbie

    Joined:
    Jan 9, 2008
    #3
    Hey, thanks for ur response.
    I dont have any clue what might be the 'illegal' characters for MAC, i am using it for 1st time in my life :)

    I found this regular Expression but giving error when i use with javascript (Invalid '(' )

    ^[/]*([^/\\ \:\*\?"\<\>\|\.][^/\\\:\*\?\"\<\>\|]{0,63}/)*[^/\\ \:\*\?"\<\>\|\.][^/\\\:\*\?\"\<\>\|]{0,63}$


    var path = ifile.value;
    var myRegExp = /^[/]*([^/\\ \:\*\?"\<\>\|\.][^/\\\:\*\?\"\<\>\|]{0,63}/)*[^/\\ \:\*\?"\<\>\|\.][^/\\\:\*\?\"\<\>\|]{0,63}$/;

    if (myRegExp.test(path) == false )
    {
    alert(false);
    } else
    {
    alert(true);
    }

    Any help is appreciated..
    Thanks
    V

     
  4. numero macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #4
    I haven't read through the expression very carefully, but the first thing I see is that:
    ^[/]*([
    should probably be
    ^[/]*\([

    I come to this conclusion because the closing ")" has a slash before it.

    Some regex implementations use just ( and ) to surround expressions and some use \( and \). Looks like this system is using /( and /) (notice the direction change).

    Let me know if this fixes it. If not then I'll dig a little deeper.

    -numero
     
  5. AussieSusan macrumors member

    Joined:
    May 29, 2006
    Location:
    Melbourne, Australia
    #5
    Don't really know javascript, but if the / is being used a string delimiter, then you will need to quote all of the /'s used within the regex pattern

    Susan
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    Indeed, and here's what you need as a result,

    Code:
    var myRegExp = /^[\/]*([^\/\\ \:\*\?"\<\>\|\.][^\/\\\:\*\?\"\<\>\|]{0,63}\/)*[^\/\\ \:\*\?"\<\>\|\.][^\/\\\:\*\?\"\<\>\|]{0,63}$/;
    
    The only from yours was as the above posters state all '/' were replaced with '\/' except for the first and last ones of course. I use BBedit and it's color-coded syntax was able to tell when the expression was correct (all of the text was blue), which was very helpful here. Just thought I'd mentioned that.
     

Share This Page