Meaning of ['_a-z0-9-\\+] Regex in Java

时间:2015-05-12 23:23:45

标签: java regex

I was looking at the Struts 2 RegEx for email validation and was unclear on a subset of it. The regex as stated in https://struts.apache.org/docs/email-validator.html is as follows:

// for the simplicity I'm using same image to make 4 tiles 2x2
jpeg.header.Xsiz *= 2;
jpeg.header.Ysiz *= 2;
vector<j2k_tile_part> tiles = jpeg.tiles;

BOOST_FOREACH(j2k_tile_part& part, jpeg.tiles)
{
    part.Isot = 2;
}

for (int i = 0; i < 3; i++)
{
    BOOST_FOREACH(const j2k_tile_part& part, tiles)
    {
        j2k_tile_part clone(part);
        switch(i)
        {
        case 0:
            clone.Isot = 3;
            break;
        case 1:
            clone.Isot = 0;
            break;
        case 2:
            clone.Isot = 1;
            break;
        }
        jpeg.tiles.push_back(clone);
    }
}

jpeg.save_file(output_file);

My question is regarding the part \\b^['_a-z0-9-\\+](\\.['_a-z0-9-\\+])@[a-z0-9-](\\.[a-z0-9-])\\.([a-z]{2}|aero|arpa|asia|biz|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|nato|net|org|pro|tel|travel|xxx)$\\b .

I know that ['_a-z0-9-\\\\+] means either a letter from a-z, a number from 0-9, or an underscore. I am not sure what the single quotation mark before the underscore means, or what _a-z0-9 before the closing square bracket means.

1 个答案:

答案 0 :(得分:2)

It's just the (interchange '()) => '() (interchange '(a)) => '(a) (interchange '(a b)) => '(b a) (interchange '(a b c)) => '(b a c) (interchange '(a 1 b 2 c 3 d 4)) => '(1 a 2 b 3 c 4 d) (interchange '(hello you -12.34 5 -6 enough)) => '(you hello 5 -12.34 enough -6) ,',- character match in your string. ['_a-z0-9-\\+] means one of character match of +, ', a-z,0-9, -.