Need help on replacing text
-
Hi all,
I need help in replacing text in a Gedcom file (Genealogy Export).
These are examples of lines in my file.
The first line, I must not touch, only has 1 date.
The second line, I must change ABT to BET
The problem that I have is that the years are variable.
I need to detect that 2 years are stated and separated by a “-” following “ABT”
Then change “ABT” by “BET” leaving the dates untouched.2 DATE ABT 1646
2 DATE ABT 1676-1678Can anyone help with some kind of “Chage” using Regex or any othe kind of change?
Thanks
Claude -
How about:
Find what box:
ABT(?= \d{4}-\d{4})
Replace with box:BET
Match case checkbox: ticked
Wrap around checkbox: ticked
Search mode radiobutton: Regular expression
Press the Replace All buttonOr maybe you also need to key off of start of line, and include the
2 DATE
stuff as well? Hard to say from your problem statement. -
@Alan-Kilborn said in Need help on replacing text:
ABT(?= \d{4}-\d{4})
Worked perfectly. Thank you very much.
This topic may be closed.
Claude
-
@Alan-Kilborn said in Need help on replacing text:
ABT(?= \d{4}-\d{4})
Sorry to ask another question about this.
The change worked from ABT to BET but I must make another change if you can spare a moment.
I need to change this line:
2 DATE BET 1676-1678to this:
2 DATE BET 1676 AND 1678Replacing the “-” between the 2 dates by " AND "
Thanks again.
Claude -
So given our first exchange, might you see which part of that pattern I provided matches four-digit years? Go ahead, take a guess! We’ll be kind.
While we do like providing help, we really enjoy it when people take the help provided and apply it to new problems. Makes us happy.
-
@Alan-Kilborn
I did look at your example and tried some variant but they did not work. Then went to look at Regex example online but man, at 65 I must say that I am a bit overwhelmed.
I tried this:
-(?= \d{4}-\d{4})I tried this:
-(?= \d{4}-\d{4})Can’t get a match and also, I need to insert a blank before and after “AND”.
\bAND\b ??Thanks
-
@Claude-Cadieux said in Need help on replacing text:
-(?= \d{4}-\d{4})
Sorry on the second try I did this:
-(?= \d{4}-\d{4}) -
@Claude-Cadieux
Backslash does not show here \-(?= \d{4}-\d{4}) -
So to match a 4-digit year you can use
\d{4}
. That means “a digit character repeated 4 times”.A blank is not
\b
. A blank space is just a blank space in your expression.\b
is actually a word-boundary.It is best to show expressions surrounded by backticks; they will appear like mine do, in red.
-
went to look at Regex example online but man, at 65 I must say that I am a bit overwhelmed
I would not believe you if you said anything different. :-)
So by now you should be matching 1968-1974 as
\d{4}-\d{4}
??Admittedly, my earlier stuff with
(?=
before it might have been misleading. Forget about that now (advanced usage). -
@Alan-Kilborn
Yes this did work: \d{4}-\d{4}
But it must be on a BET line:
2 DATE BET 1625-1629
So this also works to find the right line
BET(?= \d{4}-\d{4})But I do not know how to specify the “-” being the target to change by " AND "
-
So there may be something to learn here. With
BET(?= \d{4}-\d{4})
(you didn’t apply my “backtick” advice when you stated it), you can’t possibly influence the-
because the(?=...)
part of that doesn’t match any text, it just means that the specified text must be there. If you don’t match the text you want, you can’t replace it. (Remember, originally, all we wanted to replace was some fixed text before the (variable) year range).You might have good luck searching for
BET (\d{4})-(\d{4})
and replacing withBET \1 AND \2
.
You put grouping parentheses around variable text that you want to substitute in at replace time, as I’ve done here. Then, to refer to the first capturing group, at replace time you reference it with\1
. Similar for the second grouping.But really, this isn’t a forum about regular expressions, so time to buck up and learn a bit more than just your immediate need covers. There’s some good pointers here: https://community.notepad-plus-plus.org/topic/15765/faq-desk-where-to-find-regex-documentation
-
@Alan-Kilborn said in Need help on replacing text:
BET \1 AND \2
Thank you so much for your time and patience and the link.
There’s always something new to learn.
Claude :-)