result = subject.scan(/\[(\d+).*?\](.*?)([email protected]|\Z)/m)
Ceci saisit l'identifiant et le contenu dans les références arrière 1 et 2 respectivement. Pour arrêter la capture, @ ou la fin de la chaîne doit être respectée.
"
\\[ # Match the character “[” literally
( # Match the regular expression below and capture its match into backreference number 1
\\d # Match a single digit 0..9
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
. # Match any single character that is not a line break character
*? # Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\\] # Match the character “]” literally
( # Match the regular expression below and capture its match into backreference number 2
. # Match any single character that is not a line break character
*? # Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
# Match either the regular expression below (attempting the next alternative only if this one fails)
\@ # Match the character “\@” literally
| # Or match regular expression number 2 below (the entire group fails if this one fails to match)
\$ # Assert position at the end of the string (or before the line break at the end of the string, if any)
)
"
Ceci correspond à quelque chose commençant par @ et se terminant par la ponctuation makr. Désolé si je n'ai pas bien compris.
result = subject.scan(/@.*?[.?!]/)
http://rubular.com/ – Ryanmt
Rubular pourrait aider w @ [XX: XXXXX] mais pas en boucle à travers ou trouver le bon contenu environnant? –
J'ai ceci pour la regex, @ \ [\ d +: \ w + \ s \ w + \] mais maintenant où vais-je? –