Austin O
Austin O

Reputation: 39

What is the correct regular expression to get JUST the ID from HTML?

I am using JMeter and trying to use the Regular Expression Extraction step, and I need to get just an ID from html.

The line in question is

<a href="EditBudget.psp?jobTokenID=978025" TABINDEX="24" >Edit budget for project Perf09035710810: .</a>

I am unable to figure out the correct regular expression for just getting the ID extracted (just the 978025), and need help making this dynamic.

The closest I've gotten so far is

(EditBudget)+(.+?).\"

but that returns: EditBudget.psp?jobTokenID=978025"

Upvotes: 0

Views: 72

Answers (2)

anon
anon

Reputation:

Firstly, it must be said that using a regex is probably a bad idea, because HTML is not a regular language.

Secondly, if your ID is always in the href, and it is always after that EditBudget.psp?, and it's always numeric, then you can just use this:

EditBudget\.psp\?jobTokenID=(\d+)

Then you just need to get group 1.

If you want to have the regex match only the ID, you'll need an engine which supports backreferences, and you can use:

(?<=EditBudget\.psp\?jobTokenID=)\d+

Then the entirety of what the regex matches is your ID.

If there's no other instances of jobTokenID= except immediately preceeding an ID you want to get, you can just do

(?<!jobTokenID=)\d+

NB: If your ID isn't always numeric, replace \d with the character set representing all of the allowable characters. Cross-reference that with the engine for your language to make sure that it's supported before using it.

Upvotes: 0

Mustofa Rizwan
Mustofa Rizwan

Reputation: 10466

You can try this, group 1 match is the id

/jobTokenID=(.[^"]*)"/g

Upvotes: 1

Related Questions