Page 1 of 1

[Solved] Fnd and replace (advanced for me)

PostPosted: Thu Apr 28, 2016 7:20 pm
by strAIghtEDGE
hi,
i am unable to replace changing block of characters after static text.
and replace changing block of characters after static text and delete the rest of the line.

i have text file with thousands of hand histories and i would like to replace 3 lines in each of those.

find
"Dealt to Player3 [Ts Kh]"
replace to
"Dealt to Player3 [ ]"

problem for me is that inside [ ] is changing
there are always two characters followed by space and two characters and i would like to change that to 5 spaces instead


find
"Player3: shows [Ts Kh] (a pair of Sixes)"
replace to
"Player3: shows [ ]"

replace inside of brackets to 5 spaces and delete the rest of the line
problem is that inside of round brackets can change depending on combination (a pair of Sixes) (a pair of Aces) (Aces three of a kind) (Fullhouse ....)

find
"Seat 3: Player3 (big blind) showed [Ts Kh] and lost with a pair of Sixes"
and replace to
"Player3 (big blind) showed [ ]"

in this last case after Player3 in the round brackets can be only 3 possibilities (big blind) or (small blind) or (button)
Player3 (big blind) showed [Ts Kh]
Player3 (small blind) showed [Ts Kh]
Player3 (button) showed [Ts Kh]

here is the text:


Seat 1: Player1 ($25 in chips)
Seat 2: Player2 ($29.75 in chips)
Seat 3: Player3 ($25 in chips)
Seat 4: Player4 ($32.93 in chips)
Seat 5: Player5 ($23.17 in chips)
Seat 6: Player6 ($73.37 in chips)
Player2: posts small blind $0.10
Player3: posts big blind $0.25
*** HOLE CARDS ***
Dealt to Player3 [Ts Kh]
Player4: folds
Player5: folds
Player6: folds
Player1: raises $0.25 to $0.50
Player2: folds
Player3: calls $0.25
*** FLOP *** [Jc 6d 8s]
Player3: checks
Player1: bets $0.75
Player3: calls $0.75
*** TURN *** [Jc 6d 8s] [6c]
Player3: bets $0.50
Player1: raises $1.50 to $2
Player3: raises $4.50 to $6.50
Player1: calls $4.50
*** RIVER *** [Jc 6d 8s 6c] [Ac]
Player3: checks
Player1: checks
*** SHOW DOWN ***
Player3: shows [Ts Kh] (a pair of Sixes)
Player1: shows [Kd 6s] (three of a kind, Sixes)
Player1 collected $14.90 from pot
*** SUMMARY ***
Total pot $15.60 | Rake $0.70
Board [Jc 6d 8s 6c Ac]
Seat 1: Player1 (button) showed [Kd 6s] and won ($14.90) with three of a kind, Sixes
Seat 2: Player2 (small blind) folded before Flop
Seat 3: Player3 (big blind) showed [Ts Kh] and lost with a pair of Sixes
Seat 4: Player4 folded before Flop (didn't bet)
Seat 5: Player5 folded before Flop (didn't bet)
Seat 6: Player6 folded before Flop (didn't bet)


please ask me if something is unclear, as i have no programming skill, i try my best to explain it again.

thank you

Re: find and replace (advanced for me)

PostPosted: Thu Apr 28, 2016 8:42 pm
by John_Ha
Welcome to the forum.

You need to read the Help on Regular Expressions and find List of Regular Expressions - it defines everything. Click the Help button on the Find and Replace window.

Case 1: "Dealt to Player3 [Ts Kh]" >>> "Dealt to Player3 [5spaces ]"

1 Edit > Find and Replace > More > tick Regular Expressions
2 Type the following in the Find and in the Replace boxes:
FIND (Dealt to Player3 \[)(.. ..)(\])
REPLACE $1*****$3 The ***** should be typed as 5 spaces - the forum deletes redundant spaces so I cannot show them properly
3 Find > Replace ... (or Replace All ... when you are confident it works properly)

How does it work? The brackets separate what is found into three separate variables, which are referred to as $1, $2 (not used) and $3 in the Replace box.

(Dealt to Player3 \[) The $1 variable. \] is necessary because the ] is a special character - the preceding \ identifies it as a "normal character to be found", not a Regular Expression Special Character
(.. ..) The $2 variable is any two characters followed by a space followed by any two characters
(\]) The $3 variable is a character " ] "

In the REPLACE box, we write back variable 1, followed by 5 spaces, followed by variable 3 (which is easier than wondering if " ] " is a special character in Replace!)

When testing, build up the FIND expression by small steps, starting very simply and just try to find it. I started with "Dealt to Player3 " which, of course, it found. I then added the " [ " and it did not find it - hence I knew adding the " [ " broke the search. A quick check in Help showed that I needed " \] " not " ] ". I then added the brackets and it still worked. I then added (.. ..) etc until I hasd built up the entire expression.

You should now be able to work out Cases 2 and 3 yourself. See also Finding and replacing text in Chapter 4 of the OOo v3.3 Writer Manual

If this solves the problem, please click the Edit button on your original post and add [Solved] in front of your subject.

Re: [SOLVED] find and replace (advanced for me)

PostPosted: Thu Apr 28, 2016 11:45 pm
by strAIghtEDGE
thank you so much!

your explanation was perfect!

for deleting rest of the line i added (.*) which deletes any number of following characters

Re: [Solved] Fnd and replace (advanced for me)

PostPosted: Thu May 26, 2016 11:25 am
by John_Ha