'Invalid regular expression:Lone quantifier brackets
I have a html phone pattern that will accept these formats :
+61 x xxxx xxxx,
+61xxxxxxxxx,
0x xxxx xxxx,
0xxxxxxxxx,
xxxx xxxx,
xxxxxxxx,
+xx xxx xxx xxx,
+xxxxxxxxxxx,
0xxx xxx xxx,
0xxxxxxxxx
It was working few months ago, now suddenly my phone fields are not validating . I'm having this error:
Pattern attribute value ^(?:0|\(?\+61\)?\s?|0061\s?)[1-79](?:[\.\-\s]?\d\d){4}|(\d{4}[\s]\d{4})|(\d{8})|(\d{4}[\s]\d{3}[\s]\d{3})|(\+61\[\s]\d{3}[\s]\d{3}[\s]\d{3})|(\+61\s\d{3}\s\d{3}\s\d{3})$ is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /^(?:0|\(?\+61\)?\s?|0061\s?)[1-79](?:[\.\-\s]?\d\d){4}|(\d{4}[\s]\d{4})|(\d{8})|(\d{4}[\s]\d{3}[\s]\d{3})|(\+61\[\s]\d{3}[\s]\d{3}[\s]\d{3})|(\+61\s\d{3}\s\d{3}\s\d{3})$/: Lone quantifier brackets
Solution 1:[1]
So far, no one cared to show where in your pattern the error is.
…|(\+61\[\s]\d{3}[\s]\d{3}[\s]\d{3})|(\+61\s\d{3}\s\d{3}\s\d{3})$
^
There by mistake you inserted a backslash, escaping the opening bracket, so making it an ordinary character and leaving the closing bracket Lone. (Sadly the error message is somewhat misleading, since those brackets are of course not quantifier brackets.)
Solution 2:[2]
That means exactly that, pattern invalid.
If you want to match phones from Australia, you could use:
pattern="^(?:0|\(?\+61\)?\s?|0061\s?)[1-79](?:[\.\-\s]?\d\d){4}$"
Pattern found here.
Example: https://jsfiddle.net
Solution 3:[3]
Similar to the request above, I received the error in Visual Studio Code using the following RegEx to capture words wrapped in brackets:
\[([^\\[\r\n]*(?:\\.[^\\]\r\n]*)*)\] (which is incorrect)
on the text string (SQL)
SELECT d.[fname]
,d.[lname],d.[address1],d.[address2],d.[City],d.[zip]
FROM my_table d
WHERE [hh_id] IN (SELECT [HhId]
FROM other_table)
However using this RegEx pattern in online regex tools shown in https://regex101.com/r/HGycR9/1 show it is valid RegEx.
The correct RegEx pattern is \[([^[\r\n]*(?:\\.[^\r\n]*)*)\], which will highlight:
SELECT d.[fname] ,d.[lname],d.[address1],d.[address2],d.[City],d.[zip] FROM my_table d WHERE [hh_id] IN (SELECT [HhId] FROM other_table)
Then you can use $1 in the replace field of VS Code to remove the brackets and leave the words contained within them.
SELECT d.fname
,d.lname,d.address1,d.address2,d.City,d.zip
FROM my_table d
WHERE hh_id IN (SELECT HhId
FROM other_table)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Armali |
| Solution 2 | |
| Solution 3 | w. Patrick Gale |
