This question has already been answered:

There is a string like:

CN=袘校袥袗孝袨袙袗 袞袗袧袗袪,SURNAME=袘校袥袗孝袨袙袗,SERIALNUMBER=IIN589658742568, C=KZ,L=袗袥袦袗孝蝎,S=袗袥袦袗孝蝎 袨袘袥蝎小蝎,O="覛袗袥袗 楔袗袪校袗楔蝎袥蝎覓蝎 袘袗小覛袗袪袦袗小蝎" 袦袝袦袥袝袣袝孝孝袉袣 袦袝袣袝袦袝小袉,OU=BIN963258786458,G=袘袝袪袉袣覛蝎袟蝎,E=zhanar_93@MAIL.RU 

You need to look for the word CN or ( S, L, CITY, SERIALNUMBER ). If there is such a word, then immediately cut this word to a comma, that is, SERIALNUMBER=IIN589658742568
How can you make it easier on one or not more than two lines?

Reported as a duplicate by Arthur , 0xdb , Air , Kirill Stoianov , aleksandr barakin participants on Jan 15 at 2:02 pm .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Have you looked carefully at the answer to the question in which match is used? Did you see what the match returns? This is from [1] there is something in parentheses, it means you can enclose everything you need in brackets. besides, if you take [0] then there is a complete coincidence - just what you are asking here - Mike

1 answer 1

All these 3 methods do what you need. Choose any.

 let str = 'CN=袘校袥袗孝袨袙袗 袞袗袧袗袪,SURNAME=袘校袥袗孝袨袙袗,SERIALNUMBER=IIN589658742568, C=KZ,L=袗袥袦袗孝蝎,S=袗袥袦袗孝蝎 袨袘袥蝎小蝎,O="覛袗袥袗 楔袗袪校袗楔蝎袥蝎覓蝎 袘袗小覛袗袪袦袗小蝎" 袦袝袦袥袝袣袝孝孝袉袣 袦袝袣袝袦袝小袉,OU=BIN963258786458,G=袘袝袪袉袣覛蝎袟蝎,E=zhanar_93@MAIL.RU'; console.log(str.split(",")[0]); console.log(str.replace(/,.*/g, "")); console.log(str.match(/(.*?),/)[1]);