lundi 21 février 2022

Python search string exact regex

I have the following statement:

name:jhonatan (intellectual person) {age:20} ;
name:jose  (kind person) {age:30} ;
name:pedro (cautious person)      {age=40} ;
name:marcos (cautious person)      {age=40};

I need to get only the names that start with J, in this case the output would be:

name:jhonatan (intellectual person) { age:20};
name:jose  (kind person) {age:30};

the goal is to use re.findall. I was trying with the following code:

re.findall(r'name:j[\w\s]+)

but I didn't get a successful exit

Aucun commentaire:

Enregistrer un commentaire