javascript - Replace apostrophes with regex except if separated by a comma -


i have string need clean using javascript.

here below example of string giving me hell. need replace occurrences of ' not separated comma (like "apostrophe's" in example).

here's example:

var paitems = [   [     38.20739,     -85.76427,     1,     'asd',     '314 iowa ave, louisville, ky',     'this apostrophe's',     '2000',     '2',     '2',     '1',     'yes',     '',     '',     'area tennis|satellite dish|controlled access',     'asd',     'asd',     'lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industry's standard dummy text ever since 1500s, ',     'lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industry's standard dummy text ever since 1500s, ',     'lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industry's standard dummy text ever since 1500s, ',     'lorem ipsum dummy text of printing , typesetting industry. ',     ''   ],   [     38.20681,     -85.71437,     2,     'somewhere',     '3634 poplar level rd, ky ',     'lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industry's standard ever since 1500s, ',     '1200',     '3',     '2',     '1',     'yes',     'garage',     '2250',     'private pool|area pool|satellite dish',     '2',     'some subdivision here',     'lorem ipsum dummy text of printing , typesetting industry. ',     'lorem ipsum dummy text of printing , typesetting industry.',     'lorem ipsum dummy text of printing , typesetting industry.',     'lorem ipsum dummy text of printing , typesetting industry.',     'glenda c.'   ], ]; 

what best way approach it? i've tried regex can't right.

i think can use:

(\w)'(\w) 

demo

to match apostrophes surrounded letters, , replace example e's es, using captured groups($1$2), in:

var str = "'this apostrophe's'"; var res = str.replace(/(\w)'(\w)/g, "$1$2"); 

with result:

'this apostrophes'


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -