regexpression replace |
Site Admin
|
Fortunately, phpED has NO ability to make such stupid troubles like doubling line breaks. It is possibly done by your FTP server that misinterprets \r or so.
PHPED does not deal with \n nor \r during editing the file and does not store them in the editing buffer. If your original file (before opening in phpED) is Windows-like (\r\n) PHPED by default will save it as \r\n. If it is Unix-like (\n) PHPEd will save as \n and finally if file is Mac-like (\r) PHPEd saves as \r. If you want to change file type you have to open SaveAs dialog, select proper output type and press OK. |
||||||||||||
|
regexp replace |
|
i have similar question regarding how regexp replaces work in phped..
I have an expression looking for url ids within a certain context
and i´d like to do a
that´d result in id=13'><b>somestring for me the search works but the replace doesn´t, it seems phped reads the replacement expression literally? - oliver |
||||||||||||||||
|
Site Admin
|
\1, \2 \3 etc stand for marking places where the corresponding subpatterns would be inserted to.
For example if you enter find: id=(.)+'><b> replace to: \1something whatsoever is found on the "." will be inserted before "something": In other words id=13'><b> will be replaced with 13something If you need \1 to be inserted as \1, you have to escape it. As of $1, it is treated literally anyway. |
||||||||||||
|
\1 gets treated literally for me |
|
hi dmitrie, i did try \1 also, but it just replaces the pattern for \1something...
am I missing something? |
||||||||||||
|
|
1. If you'd like to replace "id=13><b>" with "id=13><b>something", I recommend you use this search pattern: "id=(\d+)><b>" and this replace pattern: "\0something". \0 will be substituted with full matched string, but \1 will equal to "13", as it's the first subpattern.
2. In order for subpatterns to be replaced, you need to use parenthesis like this: ": ((\d+) - (\d+))" and this is the source string: "hello: 12 - 13". As result of match, \0 = ": 12 - 13", \1 = "12 - 13", \2 = "12", \3 = "13". Hope that helps. |
||||||||||||
|
|
dmitrie, thanks for the explanation... I see better now how it should work.
but what I meant was that \1 is not getting replaced. the replace just shows \1 literally, and not the matched pattern. I tried using \0 for the whole pattern, same thing happens. |
||||||||||||
|
just to be clear |
|
the problem isn´t solved yet... I´m still not able to use regex replaces. I understand how it should work, but it´s just not working for me.
thks oliver |
||||||||||||
|
|
Sorry, but PhpED 3.3 doesn't support text replacing using regular expression syntax. The matched text will be replaced by the whole 'Replace with' string. And supported RegExp syntax in PhpED 3.3 is very limited too.
Improved RegExp support is one of PhpED 4.0 major features. |
||||||||||||
|
? |
|
mbisha,
i see, I'll be looking forward to 4.0 then. but what about the funcionality you mentioned?
this would solve some of my needs right now. do you mean this actually doesn't work at all? - Oliver |
||||||||||||||
|
|
Replacing using subpatterns is definetely not working, and syntax for patterns used in search is limited too. I don't know what is supported in 3.3, but 4.0 will feature perl-compatible regular expressions.
If you need it now, you may try to write a simple perl script, or use sed (it's available in cygwin). |
||||||||||||
|
|
thanks mbisha. I assume you were referring to general regexp syntax on your original explanation then...
I don't know perl and have never used sed... but I'm using grep on bbedit, which is pretty good, and using php regexp scripts. just would be nice to do that on the search itself, and since it will in 4.0, i'm happy by the way, will 4.0 be able to do multiple line search/replace? guess I should check on other posts on the forum... thanks oliver |
||||||||||||
|
regexpression replace |
|
||
Content © NuSphere Corp., PHP IDE team
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by