I know this has been asked at least a thousand times but I can’t find a proper regex that will match a name in this string here:
<td><div id="topbarUserName">Donald</div></td>
I want to get the name ‘Donald’ and the regex that’s the closest is >[a-zA-Z0-9]+ but the result is >Donald.
I’m coding in PureBasic (It’s syntax is similar to that of Basic) and it uses the PCRE library for regular expressions.
Can anyone help?
Josh’s pattern will work if you only make use of the numbered group, not the whole match. If you have to use the whole match, use something like
(?<=>)(\w+?)(?=<)Either way, regex is widely known to not be good for parsing HTML.
Explanation:
(?<=)is used to check if something appears before the current item.\w+?will match any “word”-character, one or more times, but stop whenever the rest of the pattern matches something, for this situation the?could have been left out.(?=)is used to check if something appears after the current item.