0

I'm having issues matching a specific link with regex.

The link's title looks like this: italicized — Some More Words (1234)

I'm using this regex expression, but it's not finding any matches:

<a href=\"([^\"]*)\"><em>italicized<\/em> &mdash; Some More Words ([0-9]{4})<\/a>

Additionally, the numbers portion of the link title can vary, thus the reason for the number capture group.

5
  • Please give a sample of the actual HTML you want to match. Commented Jul 26, 2014 at 5:00
  • So the numbers can vary, but italicized and Some More Words are the exact and fixed labels? Commented Jul 26, 2014 at 5:00
  • @mario, yes, the italicized and Some More Words do not change. Commented Jul 26, 2014 at 5:01
  • Well, then your example regex would match the above example link except for the capture parens (not literals). Commented Jul 26, 2014 at 5:03
  • Hmmm...Here's the regex on a live tester: regex101.com/r/vZ9zO1/1 Commented Jul 26, 2014 at 5:04

1 Answer 1

1

Your parens ( and ) are meta characters for capture groups.

They won't match literal paranthesis in the source text. For that they had to be escaped.

Sign up to request clarification or add additional context in comments.

Comments

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.