Groovy with regex

I am trying to learn groovy in SoapUI and now I have a regex problem in groovy.

I am trying to create a regex in groovy to parse this text:

[EM6111949VA61 = cfefcgjnjcidaiieodmlgfijaiknankpiodhghbagndikijiieicfhiiiojmfcfgjjkokkoilinbkkedcaafplikgjhomkhnopjhfhpjgkadalbkeenengiapjpeaiemokenfck; Path = / li / l; security; HttpOnly]

The result should be:

EM6111949VA61 = cfefcgjnjcidaiieodmlgfijaiknankpiodhghbagndikijiieicfhiiiojmfcfgjjkokkoilinbkkedcaafplikgjhomkhnopjhfhpjgkadalbkeenengiapjpeaiemokenfckjbe

My groovy source code in SoapUI:

erg='[EM6111949VA61=cfefcgjnjcidaiieodmlgfijaiknankpiodhghbagndikijiieicfhiiiojmfcfgjjkokkoilinbkkedcaafplikgjhomkhnopjhfhpjgkadalbkeenengiapjpeaiemokenfckjbeho; path=/bla/bla; secure; HttpOnly]'


def muster = /(?<=\[)[\w]+=[\w]+/

(erg ==~ muster).each {
log.info "Muster $it"
}

Result of log.info: Muster false

I try text using Expression :: expression

(?<=\[)[\w]+=[\w]+ to http://www.regexe.de/

And the result is what I need

EM6111949VA61 = cfefcgjnjcidaiieodmlgfijaiknankpiodhghbagndikijiieicfhiiiojmfcfgjjkokkoilinbkkedcaafplikgjhomkhnopjhfhpjgkadalbkeenengiapjpeaiemokenfckjbe

What is the correct syntax in groovy

Thanks so much for your answers.

Michael

+4
1

, ==~ , . /^(?<=\[)[\w]+=[\w]+\z/.

=~, , ==~ ( ).

, [\w] \w, \w "" .

Groovy demo:

def erg='[EM6111949VA61=cfefcgjnjcidaiieodmlgfijaiknankpiodhghbagndikijiieicfhiiiojmfcfgjjkokkoilinbkkedcaafplikgjhomkhnopjhfhpjgkadalbkeenengiapjpeaiemokenfckjbeho; path=/bla/bla; secure; HttpOnly]'
def regex = /(?<=\[)\w+=\w+/
def muster = erg =~ regex
(0..<muster.count).each { print muster[it] }

:

EM6111949VA61=cfefcgjnjcidaiieodmlgfijaiknankpiodhghbagndikijiieicfhiiiojmfcfgjjkokkoilinbkkedcaafplikgjhomkhnopjhfhpjgkadalbkeenengiapjpeaiemokenfckjbeho
+2

Source: https://habr.com/ru/post/1688570/


All Articles