Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                                                                                            
                
        
我需要使用正则表达式来匹配特定的关键字和最接近的“,”字符。这是我的示例字符串:

ersion: V3  Subject: EMAILADDRESS=aa@example.com, GIVENNAME=Blob, SURNAME=Bloby, CN=B dddddddddddd, O=sd, C=IR  Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5  Key:  Sun RSA public key, 2048 bits  modulus


现在,我需要匹配EMAILADDRESS和next之间的单词,即“ aa@example.com”(对于这两点之间的单词没有限制,它们可以是任何字符。对此合适的正则表达式是什么?

最佳答案

使用捕获组:

var str = 'ersion: V3  Subject: EMAILADDRESS=aa@example.com, GIVENNAME=Blob, SURNAME=Bloby, CN=B dddddddddddd, O=sd, C=IR  Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5  Key:  Sun RSA public key, 2048 bits  modulus'
str.match(/EMAILADDRESS=([^,]+)/i)[1]
// => "aa@example.com"



[^,]匹配任何字符异常,

09-25 18:06
查看更多