Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Please help me writing RegEx for unicode character

Last post 05-15-2009, 11:15 AM by mash. 1 replies.
Sort Posts: Previous Next
  •  05-15-2009, 2:35 AM 53048

    Please help me writing RegEx for unicode character

    I have to encode a file name in javascript. File name is expected to have any unicode characters.

    For example "####新奥尔良路易斯安那 ~`!@#$%^&()_-=+}]{[;.,.doc" 

    If I assign this to Iframe src then some meta characters are getting encoded. Like '#' is encoded as '%25'. Chinese char remain as it is.

    Therefore I cannot use escape(filename) because it is aswell encoding chinese chars, hence the file not found exception is thrown.

    I want to selectively escape characters like only key board non alpha numeric? Is there any way to find only keyboard non alpha numeric values from a regular experssion?

    Any help will be much appreciated. 

    Thanks in Advance,

    Naga.

  •  05-15-2009, 11:15 AM 53062 in reply to 53048

    Re: Please help me writing RegEx for unicode character

    While this certainly isn't a universal solution it may suit your needs.  I only attemped to match the non-alphanumerics in the ASCII range. And note not all those characters are affected by the escape function.

    function escapeNonAN(propertyName)
    {
      function escapeMatch(match)
      {
        return  escape(match);
      }
      return propertyName.replace(/[!-\x2d\/\[\`{~]/g, escapeMatch);
    }

    escapeNonAN("####新奥尔良路易斯安那 ~`!@#$%^&()_-=+}]{[;.,.doc")


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
View as RSS news feed in XML