I want to convert the following string to the provided output.
Input: "\test
edobfred
ew"
Output: "testredbobfrednew"
I've not found any solution that will handle special characters like
,
,
, etc.
Basically I just want to get rid of anything that is not alphanumeric. Here is what I've tried...
Attempt 1: "\test
edobfred
ew".replace(/[_W]+/g, "");
Output 1: "testedobredew"
Attempt 2: "\test
edobfred
ew".replace(/['`~!@#$%^&*()_|+-=?;:'",.<>{}[]\/]/gi, "");
Output 2: "testedobred [newline] ew"
Attempt 3: "\test
edobfred
ew".replace(/[^a-zA-Z0-9]/, "");
Output 3: "testedobred [newline] ew"
Attempt 4: "\test
edobfred
ew".replace(/[^a-z0-9s]/gi, '');
Output 4: "testedobred [newline] ew"
One other attempt with multiple steps
function cleanID(id) {
id = id.toUpperCase();
id = id.replace( // , "T");
id = id.replace( /
/ , "N");
id = id.replace( /
/ , "R");
id = id.replace( // , "B");
id = id.replace( /f/ , "F");
return id.replace( /[^a-zA-Z0-9]/ , "");
}
with results
Attempt 1: cleanID("\test
edobfred
ew");
Output 1: "BTESTREDOBFREDNEW"
Any help would be appreciated.
Working Solution:
Final Attempt 1: return JSON.stringify("\test
edobfred
ew").replace( /W/g , '');
Output 1: "testredbobfrednew"
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…