Regex code for ruby 1.8.7 -


i new regular expression

i trying write regular expression ruby code detect double inverted commas between double inverted commas.

i have regular expression runs fine in ruby 1.9.3

 /(?<!^|,)"(?!,|$)/ 

for string of array.

s = ( "name: ","1234 ",,,"s.m. red "b" tease ")

the italic s[4] has double inverted comma inside double inverted commas.

in ruby 1.9.3 above written regular expression detect s[4] i.e ("b")

i tried write regular expression ruby 1.8.7 gives error

 undefined (?...) sequence. might trying use named groups ruby 1.8.7. 

thanks lot if me write regular expression code ruby 1.8.7

i want string of array

s = ( "name: ","1234 ",,,"s.m. red b tease ")

so can import program .csv file.

ruby 1.8.7 doesn't have lookbehind; that's why fails you. came hack. has advantage of preserving text that's inside unwanted " characters.

'"ab","c"d"e",,,"f"'.gsub(/(^\")|(\",+\")|(\"$)/) {|s|s.gsub('"','#')}.gsub('"',"'").gsub('#','"') => "\"ab\",\"c'd'e\",,,\"f\"" 

what i'm doing here substitute " @ start or end, or commas between, # character; substitute remaining " ' characters; substitute # " characters. instead of # can use character or string know not present in file.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -