Quantcast

Test post

Beekeeping Forum

Help Support Beekeeping Forum:

admin 

Administrator
Staff member
Joined
Jul 28, 2008
Messages
6,393
Reaction score
3
Location
Hampshire uk
Hive Type
national
Number of Hives
6
Just testing:

rape
osr
****
scunthorpe
****
 

admin 

Administrator
Staff member
Joined
Jul 28, 2008
Messages
6,393
Reaction score
3
Location
Hampshire uk
Hive Type
national
Number of Hives
6
That seems to work better..
 

oliver90owner 

Queen Bee
Joined
Jul 15, 2009
Messages
15,628
Reaction score
27
Location
Lincolnshire
Hive Type
14x12
better..

Very subjective, relative and all that....

Like, err, depends on how worse it was!

Compromises, compromises.

Regards, RAB
 
Joined
Jun 8, 2010
Messages
2,374
Reaction score
0
Location
Dartmoor edge, uk
Hive Type
national
Number of Hives
5...2 wooden National, 2 poly Nat & 1 poly nuc...bursting at the seams
Well done...you speaka dee ingliss...
 

Hombre 

Queen Bee
Joined
Feb 27, 2009
Messages
2,818
Reaction score
1
Location
West Midlands
Hive Type
14x12
Number of Hives
Ten
osr, rape, scrape, grapes.

osr r.a.p.e s.c.r.a.p.e g.r.a.p.e.s

I think that it's still more than a little screwed up. I imagine that you want to change occurrences of a word bounded by whitespace, where whitespace is any of, start of line, space, tab, comma, semicolon, period, oblique, etc., or words bounded by brackets or quotes etc., but not the word unbounded or embeded.

Simple until it comes to the bit I guess. It looks like the "preview post" option is useful for testing the efficacy of your solution?
 

pbh4 

House Bee
Joined
Sep 2, 2010
Messages
172
Reaction score
0
Location
Hinckley, Leicestershire
Hive Type
national
Number of Hives
5
That seems to work better..
I don't think it is working yet!

scosr
skyscosrr
theosrutic

you should not do the substitution when the r word is in the middle of a word. What you need (according to the vBulletin manual) is perl regular expressions.

The following perl regular expression seems to do what you want. It substitutes "osr" for "therword" but only if is preceded by non-word characters (such as a space) or the beginning of the line and also followed by space or end of line.

s/(^|\W+)therword($|\W+)/\1osr\2/i

For example, if you feed it

therword
therword
therword.
notherword

it spits out

osr
osr
osr.
notherword

Hope that helps.

Paul

Edit: the example above has formatted away the spaces around the second and third line. Trust me, it does work!
 

admin 

Administrator
Staff member
Joined
Jul 28, 2008
Messages
6,393
Reaction score
3
Location
Hampshire uk
Hive Type
national
Number of Hives
6
I did it so that words within words work but not words alone.
Hence why you can type Scunthorpe but not: Well you get the idea.

I mainly used replacement variables and curly braces around single words.
Some words you can qualify just by using parentheses alone.
 

pbh4 

House Bee
Joined
Sep 2, 2010
Messages
172
Reaction score
0
Location
Hinckley, Leicestershire
Hive Type
national
Number of Hives
5
I did it so that words within words work but not words alone.
Hence why you can type Scunthorpe but not: Well you get the idea.

I mainly used replacement variables and curly braces around single words.
Some words you can qualify just by using parentheses alone.

Well, I agree, you have gotten Scunthorpe working but not theosrutic or scosr.

See my suggested perl regular expression in the post above.

Paul
 

admin 

Administrator
Staff member
Joined
Jul 28, 2008
Messages
6,393
Reaction score
3
Location
Hampshire uk
Hive Type
national
Number of Hives
6
Thanks Paul,I am just working through your code.
 

Hombre 

Queen Bee
Joined
Feb 27, 2009
Messages
2,818
Reaction score
1
Location
West Midlands
Hive Type
14x12
Number of Hives
Ten
Perl regex, thanks pbh4, that narrows the search a bit.. I would have been looking at sed/awk dialect.

Admin, this is the sort of thing you need to have wee competitions for, with the winner getting a passing mention and you get someone else to do the testing :)
 

admin 

Administrator
Staff member
Joined
Jul 28, 2008
Messages
6,393
Reaction score
3
Location
Hampshire uk
Hive Type
national
Number of Hives
6
Nearly there,just need to dig a little deeper.
Your right Hombre,give me some php and sql and I am happy as a sandboy.
But Perl :blush5:
 

admin 

Administrator
Staff member
Joined
Jul 28, 2008
Messages
6,393
Reaction score
3
Location
Hampshire uk
Hive Type
national
Number of Hives
6
****
scrape

ok looking better already,just need to add the code from paul..
 

admin 

Administrator
Staff member
Joined
Jul 28, 2008
Messages
6,393
Reaction score
3
Location
Hampshire uk
Hive Type
national
Number of Hives
6
Could I of done the pearl code in php using a "preg_match" ?
 

Hombre 

Queen Bee
Joined
Feb 27, 2009
Messages
2,818
Reaction score
1
Location
West Midlands
Hive Type
14x12
Number of Hives
Ten
Hi Mark,
My regex is rusty to non-existent, but I think that \b is better than (^|W) and ($|W). As can be seen in the images the degree of match is better in that it doesn't swallow the bounding characters as does Paul's code.

The Regex Powertool doesn't do the substitutions, but merely highlights the matches.

The \1 and \2 I believe represent, in this case, the match and the unmatched text. This is where my regex becomes slightly non-existent as I'm easily baffled.

The final "i" makes the match case insensitive.

I'm more than happy to be shown the error of my ways and hope Paul doesn't think me decrying the good work and time that he has put in. I had to be inspired before I got my Perl books out.

Getting closer, bit by bit. This is surely teamwork, where unlike bee keeping the answers begin to converge towards a single final solution.

I do notice that from the probe count, that my solution seems to require more CPU, if that's a concern.
 
Last edited:

Hombre 

Queen Bee
Joined
Feb 27, 2009
Messages
2,818
Reaction score
1
Location
West Midlands
Hive Type
14x12
Number of Hives
Ten
Any advance on s/\btherword\b/osr/i

s/\btherword\b/osr/i

seems to be the answer.

The target text has a pull down menu that allows "Highlight matches" by default, but "Show edits" and "Show replacements" give the full picture and was what allowed me to deduce that the \1 and \2 buffers are probably unnecessary in our case. :)
 

Lois 

House Bee
Joined
May 3, 2010
Messages
308
Reaction score
0
Location
Buxton Norfolk uk
Hive Type
national
Number of Hives
2 colonies now! and some spare parts.
Do you know, I had one of those but the wheels fell off :)
 

pbh4 

House Bee
Joined
Sep 2, 2010
Messages
172
Reaction score
0
Location
Hinckley, Leicestershire
Hive Type
national
Number of Hives
5
s/\btherword\b/osr/i

seems to be the answer.
Well done spotting \b Hombre! I have no problem with you improving my code and I have learnt something new. I still can't see why my version misses the cases you highlight above but life is too short to worry about it.

Paul
 

pbh4 

House Bee
Joined
Sep 2, 2010
Messages
172
Reaction score
0
Location
Hinckley, Leicestershire
Hive Type
national
Number of Hives
5
but life is too short to worry about it.
Okay, it turns out life is not too short! For the record, the reason s/(^|\W+)therword($|\W+)/\1osr\2/i failed was that the \W+ gobbles up all of the spaces following "therword" so if the next word happens to be the therword again, it is not matched because there is not at least one space preceding it. It would have worked in most reasonable cases but Hombre's version is better.
 
Joined
Jul 8, 2010
Messages
2,985
Reaction score
1
Location
Grantham/Sleaford/Newark
Hive Type
14x12
Number of Hives
None of my own
Mark - I'm wondering if you are creating a problem for yourself here. I thought the original idea of subsituting r.a.p.e. with carnolian, or whatever was OK, if a trifle unnessesary. To be honest now though I wonder why you are bothering at all, especially with *** and the like - its not a swear word even in its more widely known context.
 
Joined
Jun 8, 2010
Messages
2,374
Reaction score
0
Location
Dartmoor edge, uk
Hive Type
national
Number of Hives
5...2 wooden National, 2 poly Nat & 1 poly nuc...bursting at the seams
Many search engines do not like the r word and if it appears too often on your site, they lower you down the replies they offer to searches!! Mind you, when we went into 'computer speak' I got a little lost as I thought we spoke English!!!
 

Latest posts

Top