Simple regex help

slimdusty72

Client
Регистрация
24.08.2012
Сообщения
44
Благодарностей
8
Баллы
8
Hi,

I'm creating a template to use to post articles.
I have a folder with spun articles and get a random spun article to use.

The first line of the article is the title. Then 2 line breaks followed by article body.

I can use regex to get the article body ok.

The regex I use to get the article title is ^.*

This only works some times but not always. The debugger says regex ok, but it doesn't always get a value.

Is there a better regex to use to get the first line of an article?

Thanks for help!
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
I would bound txt with article with list.

Then take 1st line as a title, then merge the rest lines and use this as body.
 
  • Спасибо
Реакции: slimdusty72

purush84

Client
Регистрация
07.11.2011
Сообщения
259
Благодарностей
38
Баллы
0
Hi,

I'm creating a template to use to post articles.
I have a folder with spun articles and get a random spun article to use.

The first line of the article is the title. Then 2 line breaks followed by article body.

I can use regex to get the article body ok.

The regex I use to get the article title is ^.*

This only works some times but not always. The debugger says regex ok, but it doesn't always get a value.

Is there a better regex to use to get the first line of an article?

Thanks for help!
You can use some symbols to identify title and body then you can parse using RegExp...

Like this :
About The ZennoPoster MP >>>

>>> ZennoPoster MP – all-in-one solution for SEO tasks automation.
Get rid of routine with the help of ZennoPoster MP.!


REGEXP For TITLE: .*?(?=\ >>>)
REGEXP For BODY: (?<=>>>\ )[\w\W]*

Thats it.:-)
 
  • Спасибо
Реакции: slimdusty72

slimdusty72

Client
Регистрация
24.08.2012
Сообщения
44
Благодарностей
8
Баллы
8
thanks for your tip - I worked out what the problem was for me:-

I was using ^.* to get the first line of the article - however, when I checked what ZP was pulling for the article, I found that it was sometimes adding a blank line at the beginning of the article - and so using ^.* was sometimes getting a blank line for the first line.

I used your suggestion of adding >>> after the title and use .*?(?=\>>>) to get the title

After the title I have a blank line separating the title and article body and I get the article body with (?<=\r\n\r\n)[\w\W]*?$

I tried using (?<=>>>\ )[\w\W]* , but for some reason this didn't work for me.

Anyway, I appreciate your help because now it's working :-)

I've got no programming experience and don't know much about how to use RegExp, but I'm enjoying the learning process. I'm looking at the website regular-expressions.info to get a few basic pointers.

If anyone can recommend a place to learn a bit about regex (for beginners) that would be great!

Back to work!
 

purush84

Client
Регистрация
07.11.2011
Сообщения
259
Благодарностей
38
Баллы
0
  • Спасибо
Реакции: slimdusty72

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