--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Qatan,
Take a look here: contrib\xhb\regexrpl.prg
Regards,
Klas
RegExStrTran: 237.40 secondsnataq.......: 240.30 secondsRegExReplace: 912.30 seconds
so nataQ ;) could win the *easy* game -- if we pull out of the DO WHILE loop the .. + LEN( cRepl ),
do it only one time at start and use then in the loop: .. + nLen
Easy game, because for what i know about regex is, that you can do real *crazy* search[ and replace ] with reg[ular]ex[pressions].
You may google for PCRE and may have a look into hbregex.c
I'm completely unexperienced, what Harbour can do -- about grouping, back-referencing etc ...
And we have to distinguish, if they are implemented high at 'prg-level' or low-level ..
best regards
Rolf
>do it only one time at start and use then in the loop: .. + nLen
Well... I do not know how to do that... can you please do the modification and post to us?
>Easy game, because for what i know about regex is, that you can do real *crazy* search[ and replace ] with reg[ular]ex[pressions].
>You may google for PCRE and may have a look into hbregex.c
>I'm completely unexperienced, what Harbour can do -- about grouping, back-referencing etc ...
>And we have to distinguish, if they are implemented high at 'prg-level' or low-level ..
I don’t have experience either but feel like regex is very powerful! But for my specific need nataq does the job very well.
Thanks for all your help in interest.
Regards,
Qatan
>...could win the *easy* game -- if we pull out of the DO WHILE loop the .. + LEN( cRepl ),>do it only one time at start and use then in the loop: .. + nLen
Hi Pete,
well done !, convincing fast solution
hb_AtX() is new to me, but so we can work around the case-sensitive-ness of StrTran() ...
Very thanks for the tip !
best regards
Rolf
"tat" with "Tet"
in string:
"you will see the pitfall in Tatat"
nataQ: "... Tetat"
QuckRepl: " .. TeTet"
best regards
Rolf
>QuckRepl: " .. TeTet"
but there is a hidden 'trapdoor':
try to replace:"tat" with "Tet"
in string:
"you will see the pitfall in Tatat"
nataQ: "... Tetat"
QuckRepl: " .. TeTet"
(Not to mention that instead of 'tat', you should better choose to search for 'ta' since the last 't' seems redundant..)
Just one question about hb_AtX()... according to xHarbour documentation it returns the first substring contained in <cString> that matches the regular expression <cRegEx>. If no match is found, the return value is NIL... so we need to add a protection in this case, right?
I'm not sure which one is the correct. it depends on how you see it or what is the intended result.
If you want to replace every "tat" with "Tet" then nataQ does a half work, since "Tetat" still contains a "tat".
If you want to replace the first 'tat' in every 'Tatat' then you probably could search for 'Tatat' s and manipulate them (perhaps with an other function?)
is certainly deliberately constructed: i tried an example as easy and short as possible.
The idea behind is to generate with the replace loop before a new cFind which wasn't there before.
So the inner 't' of 'tatat belongs either to the first 'tat' which is replaced, or to the remaining 'tat' in the word
-- in my example it is an overlapping letter, and in this kind your really fast QuickRepl() behave 'different'.
P.S. The pitfall i see with QuickRepl as it is now, is a possible dead-loop which could show up in some circumstances, but can easily overcome it.
yes: if cFind is part of cReplace, we will get a nearly infinite loop up to memory is filled ...
best regards
Rolf
Hi Qatan,
re-inventing the wheel: heureka !, it must be round ;-)
I like to call my technic 'the string eater' - because what is eaten can't be chewed again -- usually ;-)
Maybe there is a bunch of logic possible, that QuickRepl() can be fixed -- but if that is then afterwards still faster ?
---
So your easy task is to take src/rtl/strtran.c,
duplicate ! it, and add a codepage depending case insensitive behaviour
- but please as a duplicate, because it will rob the original StrTran() quite a remarkable amount of speed.
Then you have the fastest possible solution.
And please, contribute it !
best regards
Rolf
>I like to call my technic 'the string eater' - because what is eaten can't be chewed again -- usually ;-)
>Maybe there is a bunch of logic possible, that QuickRepl() can be fixed -- but if that is then afterwards still faster ?
I like your technic also and I agree that QuickRepl() isn’t a good solution right now because it is unsafe or will not be faster...
>So your easy task is to take src/rtl/strtran.c,
>duplicate ! it, and add a codepage depending case insensitive behavior
...hmmm, at least I was obedient and opened it to see how it looks like but I have to confess that I felt like an old and inflexible “redneck” trying to speak Chinese... to much for me to start with C at this point... sorry.
I think I will stay with nataQ() for it’s simplicity and good performance. After all it does the job!
Qatan
Hi friends,My problem is the following: I need to search in a text for the string[size=18] and replace with -> style="font-size:18px;"18 is the variable part, so the expression would be[size=xx]
Hi Adam,Thanks for your response. I really didn't know how to do this with HB_RegEx(), thanks.But I don't understand it or I do something wrong, I'm sorryThis code does not work. Where this error?function main()local cString := "Hello [size=18], how are you ?"local aRet := HB_RegEx( cString , "(.*)\[size=(\d+)\](.*)" )? aRet