# Regex script sur plusieurs lignes

**URL:** <https://www.debian-fr.org/t/regex-script-sur-plusieurs-lignes/88039>\
**Category:** Programmation\
**Created:** [Mars 24, 2023, 9:12 UTC](https://www.debian-fr.org/t/regex-script-sur-plusieurs-lignes/88039 "2023-03-24T21:12:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lohofora](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/l/b2d939/32.png) [@Lohofora](https://www.debian-fr.org/u/Lohofora)\
**Post date:** [Mars 24, 2023, 9:12 UTC](https://www.debian-fr.org/t/regex-script-sur-plusieurs-lignes/88039/1 "2023-03-24T21:12:09Z")

</div>

Bonjour à toutes et tous,

Je travaille sur le script du jeu vidéo GTA IV et n’arrive pas à me sortir d’affaire avec les regex.

Voici un extrait du script sur lequel je travaille (il faut remplacer les «&nbsp;\_&nbsp;» par des espaces mais ils disparaissent dans ma citation sur le forum) :

> Dave Daddy’s back, you bitches… Daddy’s back, you bitches!  
> Niko Dave, come on. [knocking on door] Come on Dave.  
> Hossan Niko? What are you doing?  
> Niko Dave is not coming.  
> Hossan Ah, ignore him. Come on we got to get this thing ready before we dock.  
> [Hossan and Niko climb up a ladder to a higher deck.]  
> Hossan Let’s go. Here, pass me that. There. Whooh yeah! There she is…  
> \_\_\_\_\_\_Liberty City.  
> Niko Yeah.  
> Hossan You ever been?  
> Niko No.  
> Hossan Crazy place, Niko.  
> Niko What you going to do?  
> Hossan I might come back on board… or I might try to make a go of it. Like  
> \_\_\_\_\_\_ they say, it is the land of opportunity. I always wanted to make it  
> \_\_\_\_\_\_ big… own a nice place, get a dog, a house… live the dream!  
> Niko Like my cousin.  
> Hossan Oh yeah?  
> Niko Yes - he’s got the lot - house, women, cars, parties… he writes me in  
> \_\_\_\_\_these wild emails, and after I got into trouble, I thought maybe uh…  
> \_\_\_\_\_and then I got this gig, and I spend the next seven months with you  
> \_\_\_\_\_fine people and I forget… After the war finished, I couldn’t get a  
> \_\_\_\_\_ job, nobody could… so I, uh, did some dumb things and got involved  
> \_\_\_\_\_ with some idiots…  
> J’aimerais récupérer dans un premier groupe le nom du locuteur et dans un second l’ensemble de ses paroles.

J’utilise pour le moment sur python la regex : r"(\[1\].+?)\s.+?([A-Z].+)"

Elle fonctionne parfaitement lorsque le dialogue est sur une ligne unique mais ne me permet pas de récupérer les dialogues sur plusieurs lignes (par exemple, la dernière intervention de Nico dans l’extrait que je vous ai joins). J’avoue que je sèche complètement pour récupérer cela … quelqu’un aurait une piste de réfléxion que je pourrai approfondir ?

Merci d’avance !

* * *

1. A-Z

---

<div class="post-metadata">

**Author:** ![Verner](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/v/34f0e0/32.png) [@Verner](https://www.debian-fr.org/u/Verner)\
**Post date:** [Mars 25, 2023, 9:03 UTC](https://www.debian-fr.org/t/regex-script-sur-plusieurs-lignes/88039/2 "2023-03-25T09:03:42Z")

</div>

Bonjour,

> [@Lohofora](#):
>
> Voici un extrait du script sur lequel je travaille

Je vois plus du texte qu’un script.

> [@Lohofora](#):
>
> il faut remplacer les « \_ » par des espaces

Pas besoin de regex ou de python pour ça.

Text:

```plaintext
Niko Yes - he’s got the lot - house, women, cars, parties… he writes me in
_____ these wild emails, and after I got into trouble, I thought maybe uh…
_____ and then I got this gig, and I spend the next seven months with you

```

```plaintext

$ cat Text | tr '_' ' '

Niko Yes - he’s got the lot - house, women, cars, parties… he writes me in
     these wild emails, and after I got into trouble, I thought maybe uh…
     and then I got this gig, and I spend the next seven months with you

```

---

<div class="post-metadata">

**Author:** ![Almtesh](https://www.debian-fr.org/user_avatar/www.debian-fr.org/almtesh/32/10312_2.png) [@Almtesh](https://www.debian-fr.org/u/Almtesh)\
**Post date:** [Mars 25, 2023, 10:06 UTC](https://www.debian-fr.org/t/regex-script-sur-plusieurs-lignes/88039/3 "2023-03-25T10:06:08Z")

</div>

> [@Verner](#):
>
> Je vois plus du texte qu’un script.

Petite note lexicale : on utilise également le mot « [script](https://fr.wiktionary.org/wiki/script#Nom_commun_3) » dans ce contexte..

---

<div class="post-metadata">

**Author:** ![choops](https://www.debian-fr.org/user_avatar/www.debian-fr.org/choops/32/8109_2.png) [@choops](https://www.debian-fr.org/u/choops)\
**Post date:** [Mars 30, 2023, 7:53 UTC](https://www.debian-fr.org/t/regex-script-sur-plusieurs-lignes/88039/4 "2023-03-30T07:53:46Z")

</div>

> [@Verner](#):
>
> ```auto
> $ cat Text | tr '_' ' '
> 
> ```

Alternative en utilisant sed:

```auto
sed 's/_/ /g' -i Text

```

Note:  
Le «&nbsp;-i&nbsp;» c’est pour opérer la modification directement dans le fichier. Sans ce «&nbsp;-i&nbsp;», ça te donnera un aperçu du résultat sans l’écrire dans le fichier d’origine.
