New lines messing up my regex

  • Автор темы Автор темы Stereomike
  • Дата начала Дата начала

Stereomike

Client
Регистрация
29.03.2011
Сообщения
221
Реакции
30
Баллы
0
Hi, I need help.

My template writes a list of entries to a file, but sometimes it adds empty lines, which sucks big time.
I guess I found the problem, but I don't know how to reliably solve it:

The template grabs a block of text

PHP:
Развернуть Свернуть Копировать
#-music-#
Get some here.
Wow.
#--#
#-pictures-#
Get pics here.
#--#

Then it parses this block with this regex:

PHP:
Развернуть Свернуть Копировать
(?<=#-music-#)[\w\W]*?(?=#--#)

(you could try this in the expression builder:
before required text:#-music-#
after required text:#--#
Full text and shortest match ticked.

The problem is, it gives:
|
Get some here.
Wow.
|
|
(| stands for a blank line, inserted for dramatic reasons)
So a blank line above and two below!!!

How do I parse that block without getting the messy blank lines? I hope theres a better solution than deleting line 0 and lines end-1 and end-2 afterwards...

Thanks!
 
I tried
before required text:#-music-#\r\n
after required text:#--#
Full text and shortest match ticked.

But it doesn't work that way (nothing found). Did I use it wrong?
 
probably.
If you use regexp builder it would escape your \r\n to \\r\\n which is wrong.
Make sure that final regexp has single bashslash with r and and n - \r\n
 
  • Оценить
Реакции: Stereomike
Worked :) you had to edit the expression to avoid double slashes.
 
sorry Mike, I should have put the regex up for you. Was in a hurry. I had 18 holes and an 80 waiting for me if you know what I mean.
 
No problem :) Everything worked out in the end!
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)