简体   繁体   English

从HTML获得ID的正确正则表达式是什么?

[英]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. 我正在使用JMeter并尝试使用正则表达式提取步骤,并且我只需要从html获取ID。

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. 我无法找出仅提取ID的正确正则表达式(只是978025),因此需要帮助使其动态化。

The closest I've gotten so far is 我到目前为止最接近的是

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

but that returns: EditBudget.psp?jobTokenID=978025" 但是返回:EditBudget.psp?jobTokenID = 978025“

您可以尝试此操作,第1组匹配项是ID

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

Firstly, it must be said that using a regex is probably a bad idea, because HTML is not a regular language. 首先,必须说使用正则表达式可能不是一个好主意,因为HTML不是一种常规语言。

Secondly, if your ID is always in the href , and it is always after that EditBudget.psp? 其次,如果您的ID 始终href ,并且始终在该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. 然后,您只需要进入组1。

If you want to have the regex match only the ID, you'll need an engine which supports backreferences, and you can use: 如果要让正则表达式仅匹配ID,则需要一个支持反向引用的引擎,并且可以使用:

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

Then the entirety of what the regex matches is your ID. 那么正则表达式匹配的全部就是您的ID。

If there's no other instances of jobTokenID= except immediately preceeding an ID you want to get, you can just do 如果没有其他的jobTokenID=实例,除了立即在您要获取的ID之前,您可以

(?<!jobTokenID=)\d+

NB: If your ID isn't always numeric, replace \\d with the character set representing all of the allowable characters. 注意:如果您的ID并非总是数字,请用\\d替换为代表所有允许字符的字符集 Cross-reference that with the engine for your language to make sure that it's supported before using it. 在使用它之前,请将该语言与您的语言的引擎进行交叉引用,以确保它受支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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