2

I would like to search links that contain "click" or "click here" text as anchor text.

If it matches then it should return href values.

Can someone tell me how to use regex here?

3
  • Can you even use regexes with XPath? Commented Apr 26, 2013 at 15:55
  • @RocketHazmat I'm a noob. Thats why i'm asking this question. It seems like I should use contains function. Can you tell me how to use that function to match my text? Commented Apr 26, 2013 at 16:01
  • I'm not an xpath whiz, but I think this will work: //a[contains(text(), "click here")]. Commented Apr 26, 2013 at 16:02

1 Answer 1

3

You can't use regex with PHP's DOMXPath. matches() was added in XPath 2.0, but DOMXPath only supports XPath 1.0.

You can try using contains():

//a[contains(text(), "click here")]
Sign up to request clarification or add additional context in comments.

1 Comment

Does it also match if the anchor link has the text something like click here to visit ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.