আমি নিম্নলিখিত স্ট্রিং সরবরাহিত আউটপুট রূপান্তর করতে চান।
Input: "\\test\red\bob\fred\new"
Output: "testredbobfrednew"
আমি কোনো সমাধান যে মত বিশেষ অক্ষর হ্যান্ডেল না পাওয়া করেছি \r, \n, \b, ইত্যাদি
মূলত আমি এমন কোনও কিছু থেকে মুক্তি পেতে চাই যা অক্ষর নয়। এখানে আমি চেষ্টা করেছি ...
Attempt 1: "\\test\red\bob\fred\new".replace(/[_\W]+/g, "");
Output 1: "testedobredew"
Attempt 2: "\\test\red\bob\fred\new".replace(/['`~!@#$%^&*()_|+-=?;:'",.<>\{\}\[\]\\\/]/gi, "");
Output 2: "testedobred [newline] ew"
Attempt 3: "\\test\red\bob\fred\new".replace(/[^a-zA-Z0-9]/, "");
Output 3: "testedobred [newline] ew"
Attempt 4: "\\test\red\bob\fred\new".replace(/[^a-z0-9\s]/gi, '');
Output 4: "testedobred [newline] ew"
একাধিক পদক্ষেপ সহ অন্য একটি প্রচেষ্টা
function cleanID(id) {
id = id.toUpperCase();
id = id.replace( /\t/ , "T");
id = id.replace( /\n/ , "N");
id = id.replace( /\r/ , "R");
id = id.replace( /\b/ , "B");
id = id.replace( /\f/ , "F");
return id.replace( /[^a-zA-Z0-9]/ , "");
}
ফলাফল সহ
Attempt 1: cleanID("\\test\red\bob\fred\new");
Output 1: "BTESTREDOBFREDNEW"
কোন সাহায্য প্রশংসা করা হবে।
কার্যক্ষম সমাধান:
Final Attempt 1: return JSON.stringify("\\test\red\bob\fred\new").replace( /\W/g , '');
Output 1: "testredbobfrednew"
var Input = "\\test\red\bob\fred\new"এই স্ট্রিংটিতে "লাল" নেই তাই আপনার প্রথম প্রচেষ্টা সঠিক, আপনি কি লিটারের বিরুদ্ধে পরীক্ষা করছেন "\\\\test\\red\\bob\\fred\\new"?
/[^\w\s]+/giএটা চেষ্টা কর.