2016-05-11 4 views

ответ

3

Вы можете использовать:

/JSESSIONID=(.*?);/ 

Regex101 Demo:

https://regex101.com/r/nH4mT0/1


Regex Объяснение:

JSESSIONID=(.*?); 

Match the character string “JSESSIONID=” literally (case sensitive) «JSESSIONID=» 
Match the regex below and capture its match into backreference number 1 «(.*?)» 
    Match any single character that is NOT a line break character (line feed, carriage return, line separator, paragraph separator) «.*?» 
     Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?» 
Match the character “;” literally «;» 
+1

Oh это тоже аккуратно! Спасибо! – ykadaru

1

Вы можете использовать этот шаблон:

/JSESSIONID=([^;]*)/ 

? Объясняя выше регулярное выражение:

JSESSIONID=   # match the text literally 
(     # asserts that all content inside it will be in group $1 
    [^;]     # means any character not ';' 
    *      # as many as possible 
)      # end of the group $1 

Ваше желаемое значение будет внутри группы 1.

Вы можете увидеть его в action here.

+0

спасибо! Наверное, я могу просто разделить строку на «=» с JS, поскольку она все еще захватывает всю группу из JSESSIONID до самого момента с запятой. – ykadaru

+0

Да, вы можете;) ... Как вы уже сказали, это JS, мой ответ будет следующим: 'var result = string.match (/ JSESSIONID = ([^;] *) /) [1];' –

Смежные вопросы