New lines messing up my regex

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!
 

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
\r\n
 
  • Спасибо
Реакции: Stereomike

Stereomike

Client
Регистрация
29.03.2011
Сообщения
221
Благодарностей
30
Баллы
0
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?
 

gemini

Client
Регистрация
10.03.2011
Сообщения
160
Благодарностей
31
Баллы
28
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

Stereomike

Client
Регистрация
29.03.2011
Сообщения
221
Благодарностей
30
Баллы
0
Worked :-) you had to edit the expression to avoid double slashes.
 

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
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.
 

Stereomike

Client
Регистрация
29.03.2011
Сообщения
221
Благодарностей
30
Баллы
0
No problem :-) Everything worked out in the end!
 

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