Beschreibung
ein Komma getrennte Zeichenfolge gegeben, wenn multi Ziffern oder eine Zeichenfolge mit einer einzelnen mehrstelligen Zahl, können Sie diese Regex verwenden, um das führende Komma und die durch 3
oder 5
mit null teilbaren Zahlen zu ersetzen.
(?:,|^)((?:[0369]|[258][0369]*[147]|[147](?:[0369]|[147][0369]*[258])*[258]|[258][0369]*[258](?:[0369]|[147][0369]*[258])*[258]|[147](?:[0369]|[147][0369]*[258])*[147][0369]*[147]|[258][0369]*[258](?:[0369]|[147][0369]*[258])*[147][0369]*[147])*|[0-9]*[50])(?=,|\Z)
eine ausführlichere Erklärung dieses Ausdrucks finden Sie hier: siehe auch link
Ersetzen durch:
nichts
Beispiel
Live Demo
https://regex101.com/r/iG9lP4/1
Beispiel String
1,2,3,5,9,15,16,21,23,25
Nach dem Austausch
1,2,16,23
Erklärung
NODE EXPLANATION
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[0-9]* any character of: '0' to '9' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
[50] any character of: '5', '0'
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
\Z before an optional \n, and the end of
the string
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
Sie benötigen ** iterate ** über das Array. Sie können das mit einem ['for' loop] tun (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for). Mit welchem Teil hast du Probleme? Wir helfen Ihnen gerne, Ihren Code zu reparieren, aber wir schreiben den Code nicht für Sie. –
Mögliches Duplikat von [Ein bestimmtes Element aus einem Array in JavaScript entfernen?] (Http://stackoverflow.com/questions/5767325/remove-a-particular-element-from-an-array-in-javascript) – AlwaysNull
Sie können mach es auch mit [.filter] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) –