Apply changes around various text

General discussions about Advanced Find and Replace
Post Reply
predaina
Posts: 5
Joined: Fri Feb 02, 2007 4:49 pm
Location: United States of America

Apply changes around various text

Post by predaina »

I need to add html code around various text.

existing code:

Code: Select all

</div>by: author name

The author name is usually different for each file and is normally at the end of the line.
The replace should format it like this:

Code: Select all

</div><p>by: author name</p>

or even better as

Code: Select all

</div>
<p>by: author name</p>


Sometimes the text is preceeded by more text, such as:

Code: Select all

</div>by: author name Start of other text I don't change

The replace should format it like this:

Code: Select all

</div><p>by: author name</p><p>Start of other text I don't change


Even better like this:

Code: Select all

</div><p>by: author name</p>
<p>Start of other text I don't change



The RE's are making me crazy...

Thank you in advance.
Thanks,
Tim

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Re: Apply changes around various text

Post by Abacre »

predaina wrote:I need to add html code around various text.

existing code:

Code: Select all

</div>by: author name

The author name is usually different for each file and is normally at the end of the line.
The replace should format it like this:

Code: Select all

</div><p>by: author name</p>

or even better as

Code: Select all

</div>
<p>by: author name</p>


Go to main menu - Action - Options - Batch Replace
check "Modifier S"
uncheck "Modifier G"

Go to Batch replace tab, check on "Use regular expressions".
Put into the grid, search for:
</div>by:(.*)\r\n

Replace with:
</div>\r\n<p>by:$1</p>\r\n

That's all I verified it works perfectly.

predaina wrote:Sometimes the text is preceeded by more text, such as:

Code: Select all

</div>by: author name Start of other text I don't change

The replace should format it like this:

Code: Select all

</div><p>by: author name</p><p>Start of other text I don't change


Even better like this:

Code: Select all

</div><p>by: author name</p>
<p>Start of other text I don't change


This is possible too. But how do you define what is the author name
and what is the text after that? What is the separator?
I mean are you sure you have author name in the format like this:
First Name Last Name ?
Or is the author name always in lower case?
Or does the "other text" start with a capital letter?
Last edited by Abacre on Fri Feb 02, 2007 11:24 pm, edited 1 time in total.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

predaina
Posts: 5
Joined: Fri Feb 02, 2007 4:49 pm
Location: United States of America

Post by predaina »

This is possible too. But how do you define what is the author name
and what is the text after that? What is the separator?
I mean are you sure you have author name in the format like this:
First Name Last Name ?
Or is the author name always in lower case?
Or does the "other text" start with capital char?


We can only assume that the author's name is firstname lastname. The articles were not well formatted.

We can also assume that the "other text" starts with a capital letter.

Thanks in advance.
Thanks,
Tim

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre »

Ok. Suppose that first name and last name are separated by space:
The regular expression will be:
Search for:
</div>by:\s+(\S*\s+\S*)\s+(.*)\r\n
Replace with:
</div>\r\n<p>by: $1</p>\r\n<p>$2\r\n

Now if you want to further refine RE and supposing that "other text"
starts with a capital letter:

Search for:
</div>by:\s+(\S*\s+\S*)\s+([A-Z].*)\r\n
Replace with:
</div>\r\n<p>by: $1</p>\r\n<p>$2\r\n
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

predaina
Posts: 5
Joined: Fri Feb 02, 2007 4:49 pm
Location: United States of America

Post by predaina »

Perfect, thank you so much. With this I am able to create other RE's and have a better understanding of them.

A support forum like this makes me glad I purchased your product.
Thanks,
Tim

Post Reply