Question:
Regular expression to match the last six characters?
Jaaames
2008-05-26 18:33:08 UTC
Hi there.

I'm writing an AS3 script, currently using substr to extract the last six characters in quite a large loop. I'm just wondering if it will execute faster using a regular expression, seeing as they were introduced to AS3 for the performance benefits.

So can anyone tell me the regular expression that will match the last six characters in a string?

I have looked, but it's 2:30am, I'm new to regular expressions and I'm struggling to get my head round them.

Many thanks.
Three answers:
poorcocoboiboi
2008-05-26 18:41:03 UTC
I don't know precisely what format of regex ActionScript uses, but if it's POSIX format this will do it:



.{6}$



Or in Perl format:

/.{6}$/



The way you read that expression is 'any character' (which is a dot) 'six times' (which is the six in braces) 'at the end of the string' (which is the dollar sign). The slashes in the Perl format expression are delimiters that indicate the start and end of the pattern.
?
2016-10-17 05:12:46 UTC
time-honored expressions is the incorrect device for this and that's almost impossible to get all 3 of those right into a unmarried regexp. you're able to do it in 2 nevertheless: a million and 3) ^[a-zA-Z0-9]{8,}$ clarification: From the beginning as much as the top, tournament merely letters and numbers 8 or extra cases. 2) ^[^0-9]*[0-9][^0-9]*[0-9].*$ clarification: From the beginning up, tournament any non-extensive style 0-n cases, then tournament the 1st extensive style, then tournament any non-extensive style 0-n cases, then tournament the 2nd extensive style, then settle for something of the enter to the top. replace: I examined and shown "eli porter"'s answer. it works and that i defer to his extra advantageous answer. "husoski"'s does not artwork because it helps underscores.
2008-05-26 18:40:59 UTC
I don't know AS3, but if you have a Right() function, that would probably be fastest. Substr() would be next fastest. Regex will improve performance if you have to parse every character, which isn't what you're doing. (It's usually slower than substr().)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...