我有一个字符串,需要使用javascript来清理。
下面是一个给我下地狱的字符串的例子。我需要替换所有没有用逗号分隔的' (比如我的示例中的"apostrophe's“)。
下面是一个例子:
var paItems = [
[
38.20739,
-85.76427,
1,
'asd',
'314 Iowa Ave, Louisville, KY',
'this is something with apostrophe's',
'2000',
'2',
'2',
'1',
'Yes',
'',
'',
'Area Tennis|Satellite Dish|Controlled Access',
'asd',
'asd',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, ',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, ',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, ',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. ',
''
],
[
38.20681,
-85.71437,
2,
'somewhere',
'3634 Poplar Level Rd, KY ',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard ever since the 1500s, ',
'1200',
'3',
'2',
'1',
'Yes',
'Garage',
'2250',
'Private Pool|Area Pool|Satellite Dish',
'2',
'Some subdivision here',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. ',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
'Glenda C.'
],
];什么是最好的方法来接近它?我试过regex,但没能把它做好。
发布于 2015-07-23 16:49:10
我想你可以用:
(\w)'(\w)若要匹配由字母包围的撇号,然后使用捕获的组( e's )替换例如es,如下所示:
var str = "'this is something with apostrophe's'";
var res = str.replace(/(\w)'(\w)/g, "$1$2");其结果是:
“这是带有撇号的东西”
https://stackoverflow.com/questions/31592309
复制相似问题