A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Hebrew RegExp

  1. #1
    Pillow Daddy m_andrews808's Avatar
    Join Date
    May 2001
    Location
    London England
    Posts
    924

    Hebrew RegExp

    ello


    can someone tell me why this seemingly simple reg ex to look for any single hebrew char in a string doesn't work?

    Code:
    var rtl_match: RegExp = new RegExp('[\u0590–\u05FF]', 'g');
    http://unicode.org/charts/PDF/U0590.pdf

    I've tried both with and without the global flag, I've tried using the short-hand syntax I've tried resetting lastIndex to 0 before and after use. If I loop through the text and inspect each char using charCodeAt(x) hebrew characters always return a number within the range defined in the reg ex.

    No matter what I try however whenever I test a string:

    rtl_match.test(str);

    it always returns false and it's driving me up the wall.

    I'm new to reg ex's so there's the chance I'm doing something fundamentally wrong however I'm using more complex patterns in more complex ways elsewhere without problem


    Thanks


  2. #2
    Member
    Join Date
    Nov 2006
    Posts
    79
    This is how I´ve used it:

    var dechangeChar:RegExp = /_/g;
    var name:String = "Mr_Anderson";
    var fixedName:String = name.replace(dechangeChar, " ");
    trace(fixedName) //Mr Anderson

  3. #3
    Pillow Daddy m_andrews808's Avatar
    Join Date
    May 2001
    Location
    London England
    Posts
    924
    hi, thanks for the help however it doesn't solve my problem

    I believe my syntax to be correct, if I change the range to

    Code:
    var rtl_match: RegExp = new RegExp('[\u0041–\u007A]', 'g');
    to match latin characters it does exactly as it should, it just doesn't seem to like hebrew


  4. #4
    Pillow Daddy m_andrews808's Avatar
    Join Date
    May 2001
    Location
    London England
    Posts
    924
    actually scrap that last post, that range doesn't work either, anyone used unicode ranges with regex's?


  5. #5
    Pillow Daddy m_andrews808's Avatar
    Join Date
    May 2001
    Location
    London England
    Posts
    924
    ok, I switched back to using the short-hand syntax and got the regex working for latin chars:

    Code:
    var rtl_match: RegExp = /[\u0041-\u007A]/g
    sub in the hebrew range:

    Code:
    var rtl_match: RegExp = /[\u0590–\u05FF]/g;
    and the damn thing stops working!

    you can see for yourself if you copy and paste this into a new fla:

    Code:
    //var rtl_match: RegExp = /[\u0041-\u007A]/g;
    var rtl_match: RegExp = /[\u0590–\u05FF]/g;
    
    var heb: String = 'השידור לא זמין. אנא נסה שוב או בחר בשידור אחר.';
    var lat: String = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJLKMNOPQRSTUVWXYZ1234567890';
    
    trace(heb.replace(rtl_match, '!'));
    trace(lat.replace(rtl_match, '!'))
    switch between regex's by disabling/enabling lines 1/2

    interestingly using the hebrew match on 'lat' matches characters: uF059 the characters used in the regex suggesting it is no longer treating it as unicode syntax


Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center