I was thinking…
when im writing (js)
var t="1234ABC4321".match(/.*(ABC).*/)
it returns :
["1234ABC4321", "ABC"]
I can replace the , "ABC"] part by (?:...)
However, Groups are for : backreference , so i can reference them by \1 later….
question :
why does “ABC” is returned as a part of the matches ?
if he needs it for himself for later back reference , fine ! but dont keep it in my collection !
is there any logic ( i’m sure there is) ?
The logic is that the match() method checks if your string matches the regexp. If it does it returns you the part of the string that matches the regexp. If you specify grouping with () it will return the groups as well.
If your are looking to remove ABC from your string use: