diff --git a/XAS.py b/XAS.py
index 54b3c255af654dbff0369700d5dc90f96a60ed8c..8ca0b7cc683e59ca3c0a9bdc6127e60c70fb2ca4 100644
--- a/XAS.py
+++ b/XAS.py
@@ -12,6 +12,7 @@
 import numpy as np
 import matplotlib.gridspec as gridspec
 import matplotlib.pyplot as plt
+import re
 
 def absorption(T, Io):
     """ Compute the absorption A = -ln(T/Io)
@@ -190,9 +191,9 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
                 color='C1', alpha=0.2)
         ax1_twin.set_ylabel('Io')
         try:
-            proposalNB=int(nrun.attrs['runFolder'].split('/')[-4][1:])
-            runNB=int(nrun.attrs['runFolder'].split('/')[-2][1:])
-            ax1.set_title('run {:d} p{:}'.format(runNB, proposalNB))
+            proposalNB=int(re.findall(r'p(\d{6})', nrun.attrs['runFolder'])[0])
+            runNB=int(re.findall(r'r(\d{4})', nrun.attrs['runFolder'])[0])
+            ax1.set_title(f'run {runNB} p{proposalNB}')
         except:
             f.suptitle(nrun.attrs['plot_title'])