Der folgende Code examines the content of inputData.body
for a 32-character string match entspricht, und - zu meinem besten Verständnis - stellt alle Spiele in einem Array.Javascript zurückzukehren „false“, wenn keine regex
// stores an array of any length (0 or more) with the matches
var matches = inputData.body.match(/\b[\w-]{32}\b/g)
// the .map function executes the nameless inner function once for each element of the array and returns a new array with the results
return matches.map(function (m) { return {str: m} })
Ich brauche jetzt den Code etwas im Fall von nicht angepassten Ausdrücke zurückzukehren, zum Beispiel. die Zeichenfolge "false"
.
war ich diese zusätzlich zu bekommen nicht in der Lage zu arbeiten ...
// stores an array of any length (0 or more) with the matches
var matches = inputData.body.match(/\b[\w-]{32}\b/g)
if (matches == null){
return 'false'
}
// the .map function executes the nameless inner function once for each element of the array and returns a new array with the results
return matches.map(function (m) { return {str: m} })
Wie soll ich mich über etwas im Fall der Leere bedingt Rückkehr?
Ist der Code in Funktion? –
Ich denke, dein Code sollte funktionieren. – Barmar
Sind Sie sicher, dass der Aufrufer bereit ist, eine Zeichenfolge als Ergebnis der Funktion zu erhalten? Wahrscheinlich erwartet es ein Array. – Barmar