我对正则表达式比较陌生,需要帮助通过两个分隔符分割文本部分,然后捕获它们之间的内容。例如,我有一个具有“描述”属性的 JSON 对象,它本质上包含以下文本:
This is yet another test product to test for all sorts of styling/formatting issues.
PLACEHOLDER
PLACEHOLDER
PLACEHOLDER
******
Not so expensive
Works all day
Works throughout the night
No risk
100% Guarantee
------
This would be where ingredients would go for Test Product 4.
我想做的是捕获六个星号分隔符和六个破折号分隔符之间的“项目符号”列表。因此,在上面的示例中,我希望能够捕获这些行:
Not so expensive
Works all day
Works throughout the night
No risk
100% Guarantee
因此,我需要用两个分隔符分隔:
1) ******
2) ------
在这个论坛和其他论坛搜索之后,我似乎仍然无法获得任何形式的 .split() 方法和 RegEx 来准确获得我想要的东西。有人能帮我吗?最终目标是能够捕获该文本,然后将其附加到 <div>
最佳答案
没有?真的吗?
string.split(/------|\*\*\*\*\*\*/);
关于javascript - 通过 RegEx Javascript 按 2 个字符串分隔符分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16150746/