RegEx Issues when mapping
- Dominant language
- ActionScript
- Stars
- 380
- Forks
- 120
- PR merge metrics
- No merged PRs in 30d
Description
Hi Guys, I am using RegEx class to use patterns in my project as i used to do in flex.
I have seen that this class is already used in beads as "Restriction" of the TextInput in Jewel.
I have discovered several pattern transformation problems when declaring a regular expression.
Some context, i have that pattern i use to restrict text to hours and minutes:
/^(\ *)([+\-]?)(\ *)(\d+)(\:|\.|\ )([0-5]{1})([0-9]{1})(\ *)$/gi
I use that page to check my patterns: https://regexr.com/ As you can see, my pattern works fine.

The problems come when we try to initialize a variable of type RegExp:
**First issue**
`var miexc2:RegExp=/^(\ *)([+\-]?)(\ *)(\d+)(\:|\.|\ )([0-5]{1})([0-9]{1})(\ *)$/gi;`
The resulting mapping is as follows:
`/^(\\u0020*)([+\-]?)(\\u0020*)(\d+)(\:|\.|\\u0020)([0-5]{1})([0-9]{1})(\\u0020*)$/gi`
When converting space to unicode it ignores the previous escape (\\) and escapes twice.
The result should be:
`^(\u0020*)([+\-]?)(\u0020*)(\d+)(\:|\.|\u0020)([0-5]{1})([0-9]{1})(\u0020*)$/gi`
**Seccond issue**
Using the same regular expression, if instead of declaring it directly I do it through the constructor, passing it the pattern as a text string, the result is different.
`var miexc3:RegExp=new RegExp("^(\ *)([+\-]?)(\ *)(\d+)(\:|\.|\ )([0-5]{1})([0-9]{1})(\ *)$","gi");`
Result:
`/^( *)([+-]?)( *)(d+)(:|.| )([0-5]{1})([0-9]{1})( *)$/gi/`
What happened here? It seems that here it does respect the space character, however, it has not been able to respect the digit character (\d) removing the backslash character
What was expected:
`/^( *)([+-]?)( *)(\d+)(:|.| )([0-5]{1})([0-9]{1})( *)$/gi/`
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the two RegExp declarations shown in the issue and compare their generated mappings, especially escaped spaces and the \d sequence. Trace the mapping or transformation path responsible for each form; done means both declarations preserve the intended regular-expression semantics.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100