RegEx Help with Backreference I think
-
Hello, @robert-or-janet-diebel,
Well, I’m terribly sorry because, given your INPUT text provided in your last post, the two search regexes, of your
BookAndVersemacro, below, do not get any match ??-
FIND
(?-s)^\\c (\d+)(?=(.*\R)+?\\toc2 (.+)$) -
FIND
(?-is)\\v (?=(?s:.+?^(\u[\u\l -]+ \d+$)))
Did you provide the right INPUT text to test against ?
BR
guy038
-
-
@guy038 Thanx for responding.
If I run the MACRO to change \c & \v with a number and a word (\toc2 1 Samwele) it fails.
If I remove the number (\toc2 Samwele) it works. The number and {space} cause failure.
Could the RegEx be altered to allow the number and {space}? -
This post is deleted! -
@guy038 The MACRO reverses line order.
I can maybe get the changes done with a number of simpler RegEx’s run after the fact, but I would prefer it totally automated if possible.
Another alternative is to separate the Numbered books and have a separate RegEx to run against them that would allow a number and {space} -
Hi , @robert-or-janet-diebel,
Oh… How silly I am ! You’re perfectly right. At first sight, I do not remark this important line, beginning your
BookAndVersemacro :<Action type="2" message="0" wParam="42083" lParam="0" sParam="" />
So, instead of using the
^\u[\u\l -]+part, for the name, we can use, either, the regexes :^\w[\w'’ -]+
or
^[[:alnum:]][[:alnum:]'’ -]+IF no LOW LINE character (\x{005F}) occurs in the name
Within these two regexes, I also added the two apostrophe syntaxes
['’]. If you do not need them, don’t add them in the character class !So, given this example, below :
My very-Best-Novel 1 Samwele 5 L'été de tous les dangers 5 L’été de tous les dangers 1_ te_ST-
The first regex
^\w[\w'’ -]+would match the five lines above -
The second regex
^[[:alnum:]][[:alnum:]'’ -]+would match the first four lines, only
Thus, If we take the general case, you must change, in your Step 2, the search regex as below :
- FIND
(?-is)\\v (?=(?s:.+?^(\w[\w'’ -]+ \d+$)))
Best Regards,
guy038
-
@guy038 I am so very thankful for your help.
Sorry I forgot to point out the line order reversal.
I will give it a try!
All the best to you and yours. -
@guy038 That is working great! I am so thankful!
Dare I mention my last failing MACRO that should change the {space} after the Book-Chapter:verse to a TAB?
Same issue, it works if there is no number.
I will try to figure it out, but if you have any guidance, it would be appreciated.<Macro name="Space2Tab" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="^(\w+\s\d+:\d+)\s(.*)$" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="$1\t$2" /> <Action type="3" message="1702" wParam="0" lParam="512" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro> -
@guy038 Got my space-to-tab working.
Thanx for all your help! -
@guy038 Spoke too soon. Got it to change numbered book, then failed on non-numbered.
I am still working on it. -
Hello, @robert-or-janet-diebel,
I suppose that the following regex S/R should work :
-
FIND
^([\w ]+\x20\d+:\d+)\x20 -
REPLACE
$1\t
Best Regards,
guy038
-
-
@guy038 This works on numbered, but not unnumbered.
Here is what I tried.^(\d+?\s?\w+\s\d+:\d+)\s(.*)$It worked on numbered, but not unnumbered
I thought the “?” would make it optional. -
@guy038 Sorry, that does work. I somehow slipped in a space before the RegEx in the MACRO
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login