Source language: Translate to:

Problem With hpwReplaceRegExp in hpwControl

Questions about NeoBook PlugIns

Moderator: Neosoft Support

Problem With hpwReplaceRegExp in hpwControl

Postby Horst Helfen » Sun Apr 08, 2007 12:19 pm

I want to highlite words in a HTML file and use
Code: Select all
hpwReplaceRegExp "[search_string]" "[html]" "<span style=[#34]background:yellow;font-weight:bold[#34]>$1</span>" "0" "[html]"

That works, except that the part of the replaced text containing the variable [search_string] is not replaced as I expect.
Example: I search for the word neobook, NeoBook is found in the HTML file and replaced by
<span style=[#34]background:yellow;font-weight:bold[#34]>neobook</span>. How can I achieve that will be replaced by <span style=[#34]background:yellow;font-weight:bold[#34]>NeoBook</span>?
Horst Helfen

Programmers don't die, they just GOSUB without RETURN.
User avatar
Horst Helfen
 
Posts: 100
Joined: Thu May 05, 2005 4:11 am
Location: Hamburg, Germany

Postby HPW » Sun Apr 08, 2007 11:35 pm

First thought was incorrect.
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Postby Horst Helfen » Mon Apr 09, 2007 12:13 am

Thank you for your hint, Hans-Peter, but that wasn't the problem. I think that $1 in the hpwReplaceRegExp is placeholder for the search term and not for the found one.
Maybe there is a logical misunderstanding at my side.
I search case insensitive, but the in the replaced phrase it should be like the original (i.e. case sensitive).
Staying with my example, if I search for neobook, it could appear as Neobook, NeoBook or NEOBOOK in the searched string (the HTML file). That should lead to three different replacements:
Code: Select all
<span style=[#34]background:yellow;font-weight:bold[#34]>Neobook</span>

Code: Select all
<span style=[#34]background:yellow;font-weight:bold[#34]>NeoBook</span>

Code: Select all
<span style=[#34]background:yellow;font-weight:bold[#34]>NEOBOOK</span>

I wonder if this is possible with RegEx at all.
Horst Helfen

Programmers don't die, they just GOSUB without RETURN.
User avatar
Horst Helfen
 
Posts: 100
Joined: Thu May 05, 2005 4:11 am
Location: Hamburg, Germany

Postby HPW » Mon Apr 09, 2007 12:32 am

Horst,

Regular expression are so powerfull but also difficult to understand.
I have bought a good book but I still don't understand it always and mostly not on the first look.

So back to your problem.

Only this 3 alternative or any other possible combination: Neobook, NeoBook or NEOBOOK
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Postby HPW » Mon Apr 09, 2007 12:41 am

Thank you for your hint, Hans-Peter, but that wasn't the problem. I think that $1 in the hpwReplaceRegExp is placeholder for the search term and not for the found one.


No, it is for the found one. (But it is $0)

After a look in TRegExpr_DE.hlp try this:
Code: Select all
hpwReplaceRegExp "(NeoBook|Neobook|NEOBOOK)" "[html]" "<span style=[#34]background:yellow;font-weight:bold[#34]>$0</span>" "1" "[html]"


A regular expression for every combination should be possible also.
(HLP file can loaded here: http://www.regexpstudio.com/)
Last edited by HPW on Mon Apr 09, 2007 12:59 am, edited 1 time in total.
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Postby Horst Helfen » Mon Apr 09, 2007 12:58 am

I don't know which variations of the word exist in the HTML file.
The user of my application enters a word into a text entry field. Then I use
Code: Select all
dgFindFile "[InfoDir]" "*[sucheingabe]*" "[#91]suchergebnis[#93]" "1" "*.htm*"
(dgFindFile is an action of another plugin to find all HTML files that contain that word) and store them into a list box. Then the user clicks one of the list items and I use BrowserLoadFromStr to display the appropriate file after having highlighted the search word in this file.
Horst Helfen

Programmers don't die, they just GOSUB without RETURN.
User avatar
Horst Helfen
 
Posts: 100
Joined: Thu May 05, 2005 4:11 am
Location: Hamburg, Germany

Postby HPW » Mon Apr 09, 2007 1:06 am

As I said regualar expression are really powerfull.
We have to use so called modifier.

hpwReplaceRegExp "(?i)neobook" "[html]" "<span style=[#34]background:yellow;font-weight:bold[#34]>$0</span>" "1" "[html]"


Modifier (?i) switches to case-insensitiv.
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Postby Horst Helfen » Mon Apr 09, 2007 1:23 am

I tried the case modifier and now it works as expected. Thank you very much for your assistance!
BTW, I don't understand the meaning of flag for subtitution in hpwReplaceRegExp (in my case it's 1).
Horst Helfen

Programmers don't die, they just GOSUB without RETURN.
User avatar
Horst Helfen
 
Posts: 100
Joined: Thu May 05, 2005 4:11 am
Location: Hamburg, Germany

Postby HPW » Mon Apr 09, 2007 1:53 am

I don't understand the meaning of flag for subtitution in hpwReplaceRegExp


I am myself not sure where the possible settings would make sense.
The great TRegExpr-package has this switch and I simply make everything accessible from neobook by simply bypassing all parameter.
But there is a lot more possible with possible part-results where you may want to see the result-placeholders.

:wink:
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany


Return to PlugIn Discussions

Who is online

Users browsing this forum: Bing [Bot] and 1 guest