NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Search and Replace special characters


Joined: 18 Oct 2007
Posts: 18
Reply with quote
I'm sure there's an easy answer, but I couldn't find anything in the help files or the forum.

Is there a way to do search and replace on tab characters, newlines, etc. in a .php file without using regular expressions?

Bob
View user's profileFind all posts by BobRaySend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Tabs (\t) and newlines (\n) can be found with regular expressions.
Also newlines are taken into account if multiline search option is turned on.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Re: Search and Replace special characters


Joined: 18 Oct 2007
Posts: 18
Reply with quote
BobRay wrote:
I'm sure there's an easy answer, but I couldn't find anything in the help files or the forum.

Is there a way to do search and replace on tab characters, newlines, etc. in a .php file without using regular expressions?

Bob


I was hoping that if I just wanted to do a quick replace to switch tabs to spaces or vice versa, I could do it without the trouble of a regular expression search.

I can change the configuration to use tabs or spaces but it doesn't seem to change *existing* tabs.

Bob
View user's profileFind all posts by BobRaySend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Bob,
regexp is not something that can be called "trouble". Indeed, what trouble is in "replace \t with ' '"?
From regexp's perspectives, \t is tab and it's a trivial thing. Don't you agree?

But I should warn you. There is no trivial way to replace tabs with equivalent number of spaces... Let me explain a bit. Suppose we have a tab-width of 4 spaces. It means that if you have tab on the 1st (the leftmost) position, next position will be 5th (5=1+4). If there is space on the first position and tab on the 2nd, next position will be nevertheless 5th. IF there are two spaces on the 1st and 2nd positions and tab is on the 3rd, next position on right to the tab will still be 5th. It's the way tabs work. Guess, what will happen if you replace tabs with 4 spaces in those 3 cases.

If on the other hand you need to replace indenting spaces with tabs, it's a kind of trivial task you can achive with Optimal Fill option turned on. When you save the file, it will reindent all the lines with minimal number of spaces and tabs (will optimize the indent).

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 18 Oct 2007
Posts: 18
Reply with quote
dmitri wrote:
Bob,
regexp is not something that can be called "trouble". Indeed, what trouble is in "replace \t with ' '"?
From regexp's perspectives, \t is tab and it's a trivial thing. Don't you agree?


Good point Dmitri. I tend to shy away from regexp because it never seems to do what I expect but in this case it is trivial.

dmitri wrote:

But I should warn you. There is no trivial way to replace tabs with equivalent number of spaces... Let me explain a bit. Suppose we have a tab-width of 4 spaces. It means that if you have tab on the 1st (the leftmost) position, next position will be 5th (5=1+4). If there is space on the first position and tab on the 2nd, next position will be nevertheless 5th. IF there are two spaces on the 1st and 2nd positions and tab is on the 3rd, next position on right to the tab will still be 5th. It's the way tabs work. Guess, what will happen if you replace tabs with 4 spaces in those 3 cases.

If on the other hand you need to replace indenting spaces with tabs, it's a kind of trivial task you can achive with Optimal Fill option turned on. When you save the file, it will reindent all the lines with minimal number of spaces and tabs (will optimize the indent).


My only tabs are indenting tabs and I want to go the other way (change tabs to spaces) so I think replacing each tab with 4 spaces would do it. I didn't know about Optimal Fill but I don't think it will work for changing tabs to spaces.

Actually, Polystyle is probably the smart way to go here.

Thanks,

Bob
View user's profileFind all posts by BobRaySend private messageVisit poster's website
Search and Replace special characters
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic