regEx to remove spaces ?

Alex Tweedly alex at tweedly.net
Wed May 17 11:32:09 EDT 2006


jbv wrote:

>Hi list,
>
>Is it possible to use regEx to remove spaces before and
>after quotes, and, if yes, how ?
>
>Example :
>    my " beautiful " laundrette
>becomes
>    my "beautiful" laundrette
>
>  
>
I'm not entirely clear on what you're asking for ...
given the description  (remove spaces before and after quotes), I'd have 
expected that

    my " beautiful " laundrette
becomes
    my"beautiful"laundrette

Do you actually want to 
   remove spaces after the "opening" quote
   remove spaces before the "closing" quote
of any quoted sub-string ?

What if there are mismatched quotes ?   
   (Does that matter, or can you exclude the possibility ?)

It should be doable with regex - but will probably be faster without it ....

something like  (the value is already in variable t)

put empty into tNew
set the itemdel to quote
put True into outside 
repeat for each item w in t
  if outside then
    put false into outside
    put w & quote after tNew
  else
   put true into outside
   put word 1 to -1 of w & quote after tNew
  end if
end repeat
put tNew after msg
if char -1 of t = quote then 
  delete char -1 of tNew
end if





-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.392 / Virus Database: 268.5.6/340 - Release Date: 15/05/2006




More information about the use-livecode mailing list