php - Regex ignore if exist and continue -


i'm using regex php in these 2 example match match

example 1:

nom: mr match  

example 2:

nom: mme match  

example 3:

nom: match  

i'm using regex:

/nom:\s+(?:mr|mme)\s+(.*)/ui 

it works fine examples 1 , 2 no 3rd one

how tell regex ignore mr or mme if exist , continue ?

best regards

you need make non-capturing group optional; changing + * after token \s.

nom:\s+(?:mr|mme)?\s*(.*) 

or can exclude second \s , execute trim() on returned match result.

nom:\s+(?:mr|mme)?(.*) 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -