I have tab-delimited text. Certain columns have YES or NO values. I am trying to replace the YES or NO values with 1 or 0. There are too many columns to do all the permutations of YES or NO in the find expression. I was looking at using the conditional expressions but I just can't understand the Textpad Help enough to figure our how it works.
Here is an small example of the original data.
0 0 0 1 NO NO YES NO 0 0 0 0 0
I want it to be
0 0 0 1 0 0 1 0 0 0 0 0 0
Can anyone tell me if this is even possible in a single (of very few) replacement operations. If it is can you give me or direct me to a fuller description of the use of conditional expressions in Textpad (preferably with examples).
Conditional expressions and replacement
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
As Linda says, you can replace all occurrences of NO with 0 and all occurrences of YES with 1.
You can do both in a single replacement:
The replacement expression ?1(1):?2(0) specifies that the matched text is replaced with
You can do both in a single replacement:
The regular expression \b(?:(YES)|(NO))\b matchesFind what: \b(?:(YES)|(NO))\b
Replace with: ?1(1):?2(0)
[X] Regular expression
Replace All
Code: Select all
\b the start or end of a word
(?: (start of non-capturing subexpression)
( (start of capturing subexpression number 1)
YES the text "YES"
) (end of capturing subexpression number 1)
| or
( (start of capturing subexpression number 2)
NO the text "NO"
) (end of capturing subexpression number 2)
) (end of non-capturing subexpression)
\b the start or end of a word
Code: Select all
?1 if subexpression number 1 matched then
(1) the text "1"
: else
?2 if subexpression number 2 matched then
(0) the text "0"