Google-sheets – Using regex to select the text between two characters IF there is text

formulasgoogle sheetsregex

I have this text:

<a class="_f5rco33" href="/account-settings"><div class="_ojs7nk">Account</div></a>

And I want to grab the word "Account", but when I use this regex

">([^<]*)<"

It returns "" because "settings"><div" is the first valid instance.

My tags and text will change every time I run this, but I want to select what's between > and <, IF it is text, and I can't figure it out.

Best Answer

Change your * to a +, so you end up with ">([^<]+)<. I don't think you want the double quotes at the end either, since Account is followed by </div>, not by something like <"div which wouldn't be valid HTML anyway.

* means 0 or more matches, + means 1 or more. See e.g. Wikipedia for some information about these 'quantifiers'.

Here is a working demo.