当前位置: 动力学知识库 > 问答 > 编程问答 >

find all occurrences content between two markers (Ruby)

问题描述:

e.g. i have string:

'Lorem @@[email protected]@ ad his scripta @@blandit [email protected]@, eum fastidii

accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus

suscipiantur, quo @@[email protected]@ ridens inciderint id. Quo mundi lobortis

reformidans eu, legimus @@senserit definiebas an [email protected]@.'

how to get an array with all ocurrences between '@@' and '@@'

网友答案:

You can do that with scan

string ='Lorem @@[email protected]@ ad his scripta @@blandit [email protected]@, eum fastidii accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo @@[email protected]@ ridens inciderint id. Quo mundi lobortis reformidans eu, legimus @@senserit definiebas an [email protected]@.'
p string.scan(/@@(.+?)@@/).flatten

gives

["ipsum", "blandit partiendo", "dicit", "senserit definiebas an eos"]
分享给朋友:
您可能感兴趣的文章:
随机阅读: