在Javascript中,我想根据内容将字符串拆分为多个段。
每个段都是一组随机字符,以unicode上标字符结尾。
示例字符串为:
String increment = "UPDATE "
+ YOUR_TABLE + " SET "
+ YOUR_COLUMN + " = "
+ YOUR_COLUMN + " + 5";
db.execSQL(increment);
结果将是:
this⁵²is¹an³⁶⁻³⁵example²⁴string³¹
每个含有125 C的组都标志着每个区段的末端。
答案 0 :(得分:2)
使用String#match()
,如下所示:
var string = 'this⁵²is¹an³⁶⁻³⁵example²⁴string³¹';
// regex that looks for groups of characters
// containing first a sequence of characters not among '¹²³⁴⁵⁶⁻',
// then a sequence of character among '¹²³⁴⁵⁶⁻'
var regex = /([^¹²³⁴⁵⁶⁻]+[¹²³⁴⁵⁶⁻]+)/g;
var groups = string.match(regex);
console.log(groups);
// prints:
// [ 'this⁵²', 'is¹', 'an³⁶⁻³⁵', 'example²⁴', 'string³¹' ]