Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

regex element cannot be found

I have the following regex: Salary</h3>([[:print:]]+)

The html Im trying to parse is:<h3>Salary</h3>£12,500 - £14,500 pa</div>

Here is my code to get the salary: <cfset MatchSalary=REFindNoCase(#Trim(xmlObj.xmlRoot.site[1].detailpageparsers.parse[3].xmlAttributes.re)#, cfhttp.FileContent,1,True)>      
                              <cfset thisSalary = mid(cfhttp.FileContent,MatchSalary.pos[2],MatchSalary.len[2])>

Problem:
The element at position 2 cannot be found.  
 
 
The error occurred in C:\CFusionMX\wwwroot\Project\1.cfm: line 33
Called from C:\CFusionMX\wwwroot\Project\1.cfm: line 21
Called from C:\CFusionMX\wwwroot\Project\1.cfm: line 1
 
31 :                               
32 : <cfset MatchSalary=REFindNoCase(#Trim(xmlObj.xmlRoot.site[1].detailpageparsers.parse[3].xmlAttributes.re)#, cfhttp.FileContent,1,True)>      
33 : <cfset thisSalary = mid(cfhttp.FileContent,MatchSalary.pos[2],MatchSalary.len[2])>



 
0
VHSB
Asked:
VHSB
  • 3
  • 2
1 Solution
 
umbraeCommented:
I would suggest doing a <cfdump var="#matchSalary#"> and seeing if the data you're coming up with is what you want - it sounds like its not grabbing the right info with your regex, what does it show when you cfdump matchsalary?
0
 
VHSBAuthor Commented:
I changed the regex to: Salary[&lt;/h3>]([[:print:]]+) and that got rid of the error message, but it has also given me a new problem.

That regex only returns something if there is text between the tags, for example:
for the HTML:   <h3>Salary</h3>Depending on experience and qualifications</div>
The regex returns: Depending on experience and qualifications</div>

But for the HTML:  <h3>Salary</h3>£12,500 - £14,500 pa</div>
The regex returns nothing.

Do you think it might be something to do with the £ character in the html?
0
 
umbraeCommented:
Quite possible. Try using this regex:

Salary</h3>([^<]*)

that should get you anything in between the </h3> tag and the </div> tag

0
 
umbraeCommented:
Addendum: If the content in between the </h3> tag and the </div> tag contains html, it'll only grab up to the next html tag - however given your questions I'm under the impression you expect this to not contain any html.
0
 
VHSBAuthor Commented:
Umbrae
"If the content in between the </h3> tag and the </div> tag contains html, it'll only grab up to the next html tag - however given your questions I'm under the impression you expect this to not contain any html." Yes you were right.

It worked a treat, thanks for your time.

Regards
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now