-1

I have this string

<meta itemprop="name" content="some text" />

I have no ideas how to write regular expression to get only some text part of above string.

αғsнιη
  • 2,627
  • 2
  • 25
  • 38
  • No need to downvote a specific question, even if it's lacking more than a bit... He's clearly out of his depth and has no idea how to implement it. There's no hard in providing an answer with an explanation. – kayleeFrye_onDeck Nov 13 '14 at 20:12
  • 1
    I strongly suggest: http://www.regexbuddy.com/ develop, test and learn RegEx. – Frank V Nov 13 '14 at 20:17
  • Duplicate of http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Uyghur Lives Matter Nov 15 '14 at 15:51

2 Answers2

2

i can recommend you looking at http://www.regular-expressions.info/, looking at Learning Regular Expressions or reading the book i've read ... http://shop.oreilly.com/product/9780596528126.do

and if you cant handle them; use QString::contains and QString::split to get to your result

Community
  • 1
  • 1
Zaiborg
  • 2,492
  • 19
  • 28
  • Any coder can "handle" regular expressions, but they have a steep learning curve for most people, especially those who have a hard time wielding syntax that isn't human-reading friendly. That being said, I do agree that one should at least look up what the heck they're trying to do before just posting a question on SO begging for help... – kayleeFrye_onDeck Nov 13 '14 at 20:16
2

This is your regex pattern. Here you go:

(?<=content=").*?(?=")



Part 1: (?<=content=")
Explanation: This does a "Positive Lookbehind" to verify a literal match to content=" before your desired text without including it inside of the actual match

Part 2: .*?
Explanation: This will look for anything between Part 1 and Part 3 and assign that as your match as few times (lazy) as possible

Part 3: (?=")
Explanation: This makes sure that there is a quotation mark (") after your matched text using a "Positive Lookahead"



Now, regarding how one would implement this into C++, I leave that up to you. I'm only answering for the regex pattern for what you're looking for.

kayleeFrye_onDeck
  • 6,648
  • 5
  • 69
  • 80