0

I need your help for a pattern i can't do myself.

I got this file :

    description1="SIOUH : Authentification Cerbere - Acces"
    description2="Acces formulaire authentification SIOUH"
    addheader="Pragma: no-cache "
    method="get"
    url="${AUTH_URL}/login/LoginDispatchAction.do?appId=${APP_ID}&backURL=${APP_URL_ENC}"
    errormessage="Phase 1 : Impossible atteindre le formulaire authentification CERBERE pour SIOUH"
    serveur="yes"
    verifypositive="loginConnectAppliForm"
    logrequest="yes" logresponse="no" />

I have this preg_match_all which works perfectly :

preg_match_all  ( '#(.*?)="(.*?)"#s', $contents, $matches, PREG_SET_ORDER ); //Chaque option

My problem is i can have simple quotes instead of double, how can i change my pattern to handle it? Example, i need to catch this line like all others:

parseresponse='name="conversationId" value="|"'

Thank a lot for your help.

2 Answers 2

1

Use a backreference to require the closing quote to match the opening one:

'#(.*?)=([\'"])(.*?)\2#'
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect ! Didn't know it was possible to do this. I was going on '#(.*?)=(?:(?:\'(.*?)\')|(?:"(.*?)"))#' but yours is better. Thank !
1

Try to use regex liek this

^(.*?)=[\'"](.*?)[\'"]$

3 Comments

As i can have [logrequest = "yes" logresponse = "yes"] on 1 line, i can't use ^ and $ i nmy regexp. If i use [\'"] instead of my ", i got this : Array ( [0] => parseresponse='name=" [1] => parseresponse [2] => name= ) Because i got a double quote in my simple quote (parsereponse is a pattern) which is catched and shouldn't be.
Then try to use greedy capture - remove ? from second group of round brackets
With '#(\w*?)=["\'](.*)["\']#' i got a trouble with the [logrequest = "yes" logresponse = "yes"] which is on the same line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.