D'abord quelques retours, avec des compliments pour avoir écrit cela en dix minutes :
-
(?<=\p{L}) => C'est bien, mais je propose d'inclure « la lettre » dans la capture réelle, afin que l'utilisateur puisse voir où la regex a repéré une « fin de phrase » potentielle. Compliments pour avoir capté les majuscules et les minuscules. Je remplace donc ?<= par ?: dans ma proposition.
-
(?<!\\[\w+]) => Je crois que pour votre intention d'éviter les faux positifs avec certains marqueurs, cette partie doit être à gauche de votre « lettre ». De plus, le + devrait être à l'extérieur des crochets, car de nombreux marqueurs ont plusieurs caractères comme \s1.
-
Et certains marqueurs incluent le *, par exemple la fin de quelque chose comme \em*. Je me souviens vaguement que certains marqueurs peuvent ou doivent même inclure +. Si c'est le cas, vous pouvez facilement ajouter à la liste des caractères comme [\w*+].
-
\s*(?:\\\w+)?\s* => Je remplace celui-ci par « passer par-dessus n'importe quel nombre de marqueurs potentiels et tout espace blanc entre la fin du verset et le début du verset suivant.
-
\\v [\d\w]+ \p{Lu} => Trouver un verset suivi d'une majuscule. Il semble que vous soyez confiant ici quant à un « espace classique » entre \v et le numéro du verset et après le numéro du verset, donc j'ai conservé cette syntaxe.
Je voudrais soumettre une regex modifiée, sans prétendre que c'est la solution finale, mais en espérant couvrir plus de cas :
(?<!\\[\w\*]*)(?:\p{L})\s*(?:\\[\w\*]+\s+)*\\v [\d\w]+ \p{Lu}
Voici la description de ma regex, selon mon outil :
(?<!\\[\w\*]*)(?:\p{L})\s*(?:\\[\w\*]+\s+)*\\v [\d\w]+ \p{Lu}
(?<!\\[\w\*]*)(?:\p{L})\s*(?:\\[\w\*]+\s+)*\\v [\d\w]+ \p{Lu}
(?<!\\[\w\*]*)(?:\p{L})\s*(?:\\[\w\*]+\s+)*\\v [\d\w]+ \p{Lu}Options : Insensible à la casse ; Espacement exact ; Le point correspond aux sauts de ligne
-
Affirmer qu'il est impossible de correspondre à la regex ci-dessous en arrière à cette position (regard en arrière négatif)
- Correspondre au caractère backslash
-
Correspondre à un seul caractère présent dans la liste ci-dessous
- Entre zéro et un nombre illimité de fois, autant de fois que possible, en rendant ce qui est nécessaire (avide)
- Un « caractère de mot » (Unicode ; toute lettre ou idéogramme, chiffre, chiffre de lettre, ponctuation de liaison)
- Le caractère littéral « * »
-
Correspondre à l'expression régulière ci-dessous
- Correspondre à un caractère de la catégorie Unicode « lettre » (toute sorte de lettre de n'importe quelle langue)
-
Correspondre à un seul caractère qui est un « caractère d'espace blanc » (tout séparateur Unicode, tabulation, saut de ligne, retour chariot, tabulation verticale, saut de page, ligne suivante, espace de largeur nulle)
- Entre zéro et un nombre illimité de fois, autant de fois que possible, en rendant ce qui est nécessaire (avide)
-
Correspondre à l'expression régulière ci-dessous
- Entre zéro et un nombre illimité de fois, autant de fois que possible, en rendant ce qui est nécessaire (avide)
- Correspondre au caractère backslash
-
Correspondre à un seul caractère présent dans la liste ci-dessous
- Entre un et un nombre illimité de fois, autant de fois que possible, en rendant ce qui est nécessaire (avide)
- Un « caractère de mot » (Unicode ; toute lettre ou idéogramme, chiffre, chiffre de lettre, ponctuation de liaison)
- Le caractère littéral « * »
-
Correspondre à un seul caractère qui est un « caractère d'espace blanc » (tout séparateur Unicode, tabulation, saut de ligne, retour chariot, tabulation verticale, saut de page, ligne suivante, espace de largeur nulle)
- Entre un et un nombre illimité de fois, autant de fois que possible, en rendant ce qui est nécessaire (avide)
- Correspondre au caractère backslash
- Correspondre à la chaîne de caractères « v » littéralement (insensible à la casse)
-
Correspondre à un seul caractère présent dans la liste ci-dessous
- Entre un et un nombre illimité de fois, autant de fois que possible, en rendant ce qui est nécessaire (avide)
- Un « chiffre » (tout nombre décimal dans n'importe quel script Unicode)
- Un « caractère de mot » (Unicode ; toute lettre ou idéogramme, chiffre, chiffre de lettre, ponctuation de liaison)
- Correspondre au caractère « » littéralement
- Correspondre à un caractère de la catégorie Unicode « majuscule » (une majuscule qui a une variante minuscule)
Et voici un texte d'exemple que j'ai utilisé pour les tests. Probablement incomplet (à la fin de chaque exemple, je marque s'il s'agit d'une capture ou non) :
\v 8 Some text without \em punctuation\em* \rem \any \v 9 A new verse which is a new sentence, starting with a capital. [catch]
\v 8 Some text without \em punctuation\em* \v 9 A new verse which is a new sentence, starting with a capital. [catch]
\v 8 Some text without punctuation \v 9a A new verse which is a new sentence, starting with a capital. [catch]
\v 8 Some text with proper \em punctuation.\em* \just \one \more \v 9 A new verse which is a new sentence, starting with a capital. [punctuation present, so no catch]
\v 8 Some text ending an an all-cap word like \em LORD\em* \v 9 A new verse which is a new sentence, starting with a capital. [catch]
\v 10 A long sentence \whatever \v 11a over two verses or more. [No punctuation needed, so no catch]
Bon, c'était amusant. J'espère ne pas être trop loin. Je ne peux malheureusement jamais me souvenir de quelle saveur de regex PT utilise. S'il y a des problèmes de syntaxe à cause des saveurs, je pourrais facilement en appliquer une différente comme .NET ou Java et relancer mon outil.
Encore une fois : Ce n'est pas la solution, mais peut-être utile pour lancer un dialogue.
hth
First some feedback, with compliments for writing that in ten minutes:
-
(?<=\p{L}) => Is good, but I propose to include “the letter” in the actual catch, so that the user will see where the regex spotted a potential “end of sentence”. Compliments for catching upper case and lower case letters. So I replace ?<= with ?: in my proposal.
-
(?<!\\[\w+]) => I believe for your intension to avoid false positives with some marker, this part has to be to the left of your “letter”. Also the + should be outside the square brackets as many markers have multiple characters like \s1.
-
And certain markers include the *, for example end-of-something like \em*. I vaguely remember that certain markers can or must even include +. If that is the case, you can easily add to the list of characters like [\w*+].
-
\s*(?:\\\w+)?\s* => This one I replace with "skip over any number of potential markers and any whitespace between the end of the verse and the start of the next verse.
-
\\v [\d\w]+ \p{Lu} => Find a verse followed by an upper-case letter. Seems you are confident here about a “classic space” between \v and the verse number and after the verse number, so I kept that syntax.
I would like to submit a modified regex, not claiming it is the final solution, just hopefully covering more cases:
(?<!\\[\w\*]*)(?:\p{L})\s*(?:\\[\w\*]+\s+)*\\v [\d\w]+ \p{Lu}
Here is the blurb for my regex, as per my tool:
(?<!\\[\w\*]*)(?:\p{L})\s*(?:\\[\w\*]+\s+)*\\v [\d\w]+ \p{Lu}
(?<!\\[\w\*]*)(?:\p{L})\s*(?:\\[\w\*]+\s+)*\\v [\d\w]+ \p{Lu}
(?<!\\[\w\*]*)(?:\p{L})\s*(?:\\[\w\*]+\s+)*\\v [\d\w]+ \p{Lu}Options: Case insensitive; Exact spacing; Dot matches line breaks
-
Assert that it is impossible to match the regex below backwards at this position (negative lookbehind)
- Match the backslash character
-
Match a single character present in the list below
- Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
- A “word character” (Unicode; any letter or ideograph, digit, letter number, connector punctuation)
- The literal character “*”
-
Match the regular expression below
- Match a character from the Unicode category “letter” (any kind of letter from any language)
-
Match a single character that is a “whitespace character” (any Unicode separator, tab, line feed, carriage return, vertical tab, form feed, next line, zero-width space)
- Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
-
Match the regular expression below
- Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
- Match the backslash character
-
Match a single character present in the list below
- Between one and unlimited times, as many times as possible, giving back as needed (greedy)
- A “word character” (Unicode; any letter or ideograph, digit, letter number, connector punctuation)
- The literal character “*”
-
Match a single character that is a “whitespace character” (any Unicode separator, tab, line feed, carriage return, vertical tab, form feed, next line, zero-width space)
- Between one and unlimited times, as many times as possible, giving back as needed (greedy)
- Match the backslash character
- Match the character string “v ” literally (case insensitive)
-
Match a single character present in the list below
- Between one and unlimited times, as many times as possible, giving back as needed (greedy)
- A “digit” (any decimal number in any Unicode script)
- A “word character” (Unicode; any letter or ideograph, digit, letter number, connector punctuation)
- Match the character “ ” literally
- Match a character from the Unicode category “uppercase letter” (an uppercase letter that has a lowercase variant)
And here is some sample text, that I used for testing. Most likely incomplete (at the end of each example, I mark, whether it is a catch or not):
\v 8 Some text without \em punctuation\em* \rem \any \v 9 A new verse which is a new sentence, starting with a capital. [catch]
\v 8 Some text without \em punctuation\em* \v 9 A new verse which is a new sentence, starting with a capital. [catch]
\v 8 Some text without punctuation \v 9a A new verse which is a new sentence, starting with a capital. [catch]
\v 8 Some text with proper \em punctuation.\em* \just \one \more \v 9 A new verse which is a new sentence, starting with a capital. [punctuation present, so no catch]
\v 8 Some text ending an an all-cap word like \em LORD\em* \v 9 A new verse which is a new sentence, starting with a capital. [catch]
\v 10 A long sentence \whatever \v 11a over two verses or more. [No punctuation needed, so no catch]
So, this was fun. Hope I am not too far off. I can sadly never remember what regex-flavour PT uses. If there are issues with syntax because of flavours, I could easily apply a different one like .NET or Java and re-run my tool.
Again: Not the solution but maybe useful to get a dialog going.
hth
Traduit automatiquement depuis English