First of all p{L}
does not catch numbers, so (T1.Test)
will not be matched, while with w
would be.
Your regex is diveded in two big OR
parts "1 | 2
":
(?:w+()+
this non capturing group is matching anything of the shape anyAmmountOfLetter(
. If this has success will totally ignore the rest of the regex, I don't know if it was intentional. This for example will trigger your regex: aaa(333.6780)
with aaa(
as full match, but 0 groups as you are not capturing it.
(p{L}+(?:.p{L}+)?)(?!')
this requires that you start your expression with a word boundary. But is valid in between two characters (Regex Tutorial) only if one is a word character an the other is not.
In your case, your starting round bracket will not be matched against the word boundary so (クーク.Test)
will not work, but 3クーク.Test)
will.
For fix that you can use only the second part (if the first is not really needed for checking something else of what you had shown in the question inputs):
// slight edited, can use digits: (3123.123) => 3123.123
input.match(/[]*(([dp{L}]+(?:.[dp{L}]+)?))[]*(?!')/gu)
// slight edited, must start with letter: (A1.Test) works, (1A.Test) doesn't
input.match(/[]*((p{L}[dp{L}]*(?:.[dp{L}]+)?))[]*(?!')/gu)
Also the last part (?!')
is optional for the input cases you gave, but I suppose it is usefull for other purposes.
If you want to keep the regex simple for those inputs, this would also work:
// can use digits: (3123.123) => 3123.123
input.match(/(([p{L}d]+(?:.[p{L}d]+)))/gu)
// must start with letter: (A1.Test) works, (1A.Test) doesn't
input.match(/((p{L}[p{L}d]*(?:.[p{L}d]+)))/gu)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…