Regex to check if first 2 characters in a string are Alphabets

56,102

Not familiar with actionscript, but if it follows normal regex type rules, you need a regex more like:

/^[A-Za-z]{2}/

to match two alpha characters at the start of a string.

Share:
56,102
Admin
Author by

Admin

Updated on February 12, 2020

Comments

  • Admin
    Admin about 4 years

    I'm new to actionscript and i cant seem to get the regex syntax right in actionscript3. The task is straight forward, i want to make sure that the first two characters in a given string are alphabets and nothing else. Here's what I'm doing and obviously it doesn't work or i wouldn't be here! ;-).

    what am I doing wrong here?

    var fileName:String = "- Earth"; 
    var pattern:RegExp = /(A-Z)(a-z){0,1}/;
    if (pattern.test(fileName)) {
       Alert.show("Trew");    
    }
    else {
       Alert.show("phalse");
    }
    
  • Rohan Shinde
    Rohan Shinde over 7 years
    How can we negate this same expression? I want to negative condition for initial 2 letters. I tried /(?!(^[A-Za-z]{2}))/ which is not working