0

I want to remove all white spaces from string except except between words,i try the following,but its not working.

Input String

=  IF  ( @F_28º@FC_89º =  " @Very strongº "  , 100 ,  IF  ( @F_28º@FC_89º =  " @Above Averageº "  , 75 ,  IF  ( @F_28º@FC_89º =  " @Averageº "  , 50 ,  IF  ( @F_28º@FC_89º =  " @Below Averageº "  , 25 ,  IF  ( @F_28º@FC_89º =  " @Cannot determineº "  , 0 ,  IF  ( @F_28º@FC_89º =  " @Poorº "  , 0 , 0 )  )  )  )  )  )

I want to remove all spaces except words like

  • Very strong
  • Above Average etc

I tried this regex from this question:

str.replace(/\s/g, '')

but its also not working.

2
  • 2
    Show the desired output, your question is unclear. Commented Sep 2, 2015 at 11:15
  • it seems like you want to remove all spaces except spaces that appear between @ and º - would that be a fair assessment? Commented Sep 2, 2015 at 11:19

2 Answers 2

1

Something like this \s+(?![a-zA-Z])?

Applied to the string you posted, the result is:

= IF(@F_28º@FC_89º="@Very strongº",100, IF(@F_28º@FC_89º="@Above Averageº",75, IF(@F_28º@FC_89º="@Averageº",50, IF(@F_28º@FC_89º="@Below Averageº",25, IF(@F_28º@FC_89º="@Cannot determineº",0, IF(@F_28º@FC_89º="@Poorº",0,0))))))

Fiddle

This one \s+(?![a-zA-Z])|\s+(?=IF) also removes spaces before IF word:

=IF(@F_28º@FC_89º="@Very strongº",100,IF(@F_28º@FC_89º="@Above Averageº",75,IF(@F_28º@FC_89º="@Averageº",50,IF(@F_28º@FC_89º="@Below Averageº",25,IF(@F_28º@FC_89º="@Cannot determineº",0,IF(@F_28º@FC_89º="@Poorº",0,0))))))

Fiddle

Sign up to request clarification or add additional context in comments.

Comments

0

If I am understand correctly you want to trim the leading and trailing spaces in the string?

$.trim(str);

1 Comment

If you're not sure of what the OP wants please don't post an answer. When you have more reputation you'll be able to comment and ask for details like this before posting your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.