简体   繁体   中英

Regular Expression in JMeter 2.12

I'm trying to use the Regular Expression Extractor in JMeter. When I try to parse the following string:

8EC4146730CC4A27afMCCam3ZeAl4uWt3qMMi9cE7Q5YtIkS5BDaba6bI1cgv41dm07wWlFjAmCcRLd97tmLyuO0ycKflQzhaoQS68CGaRo1oqsL1ZQyLGJMM

From the html snippet:

<a href="siw_portal.url8EC4146730CC4A27afMCCam3ZeAl4uWt3qMMi9cE7Q5YtIkS5BDaba6bI1cgv41dm07wWlFjAmCcRLd97tm-LyuO0ycKflQzhaoQS68CGaRo1oqsL1ZQyLGJMM" id="STU_COURSE" title="Your course">YourCourse</a>
</dt>

Using this Regular Expression:

<a href='siw_portal.url\?([^"]+)' id="STU_COURSE" title='Your course'>Your Course</a>
</dt>

And Template is set to $1$.

The Regular Expression Extractor doesn't find the string.

Any ideas on why this isn't working, or how to debug this will be much appreciated.

Thanks

Because you made a mistake with the quotes:

<a href="siw_portal.url\?([^"]+)".......title="Your course"
//    __^                     __^           __^         __^

instead of

<a href='siw_portal.url\?([^"]+)'.......title='Your course'

You can test your regex using any online regex tester, which will help you with simple syntax errors, and also provide hints which cn be really useful for a beginner.

I like this one: http://regex101.com/

You have used different quotation marks in your regex to the sample you are matching, which is why you don't find a match. You are matching " when the sample uses ' .

You can make it work in both cases using ["'] or choose the correct ' or "

In your sample, try:

<a href=["']siw_portal\.url([^"^']+)["'] id=["']STU_COURSE["'] title=["']Your course["']>Your Course</a>
</dt>

This should work

<a href="siw_portal.url(.+?)" id="STU_COURSE" title="Your course">YourCourse<\/a>
<\/dt>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM