I read several key values from a document with bible passages written in spanish like this
1 Corintios 2:4-5; Mateo 15:1-10;Salmos 118:16
I want to extract the citations in each reference (could be one or more than one) and for each citation inside the reference I need to split it to get the "book name" and "chapter" in order to send both to special index. Book names may be preceeded by numbers. For each occurrence I want to "store" the values into l_hpbook and l_hpchapter variables. I am able to use the right regex expression, but not able to store the values in the respective macro variable lp_hpbook and l_hpchapter. Any hints? (functionality not available in bibleref, there is not even an spanish package)
\documentclass{article}
\usepackage{expl3}
\usepackage{l3regex}
\ExplSyntaxOn
\tl_new:N \l_hpsplit_tl
\cs_new:Npn \hpsplit #1 {
% Purpose: Extract all words that are followed by a space + number
% optionally preceded by a number and space
% Return: All matches are stored in a global token \hpmatches_tl
\str_new:N \l_hpbook
\int_new:N \l_hpchapter
\tl_new:N \l_holdmatches
\int_new:N \l_hpmatch_int
\tl_set:Nn \l_hpsplit_tl {#1}
% This statement DOES NOT work . Count of matches not stored in variable
% Count \l_hpmatch_int % Output generates error: Missing number
\regex_count:nnN {\d+\s\w+\s\d+|\w+\s\d+ } { #1 } \l_hpmatch_int
% Count \l_hpmatch_int % Output generates error: Missing number
% Splits multiple citations: book name and chapter number retrieved
% This statement WORKS!
\regex_extract_all:nnN{ \d+\s\w+\s\d+|\w+\s\d+} { #1 } \l_holdmatches%
\seq_map_inline:Nn \l_holdmatches {
item:~##1\par%
% Extract the book name of a single citation
\regex_extract_once:nnN{ \d+\s\w+|\w+} { ~##1 } \l_hpbook%
% \l_hpbook % this one generates error
% Extract the book's chapter from a single citation
% by finding the last occurrence of space and digits
\regex_extract_once:nnN{(?!.*\s\d)\d+} { ~##1 } \l_hpchapter%
% \l_hpchapter % this one generates error if uncommented.
% I want to use these two variables as follows:
% \index{\lp_hpbook!lp_hpchapter!\articlename}
}%
\tl_use:N \l_hpsplit_tl
% \hpvar{\seq_map_inline:Nn \l_holdmatch {~##1\par }}%
}
\ExplSyntaxOff
\begin{document}
% Will read several references from book like this
% Need to obtain 'book name' separate from chapter
\hpsplit{1 Corintios 2:4-5; Mateo 15:1-10;Salmos 118:16}
\end{document}