Home > Software design >  Google sheet Regex
Google sheet Regex

Time:11-21

Trying to fetch meaning of an entered text from urban dictionary. The problem is that urban dictionary shows several definitions posted by different users. I've used 'importxml' for fetching the first page that shows up when someone searches for a particular word.

Now I want this data to be split in different columns so that I can get each definition in seperate column.

If we look at the fetched data, at the end of every definition there is "by username month dd,yyyy" string.

How can I use this string to split that raw data into definitions in separate columns?

Tried RegEx but could not figure it out because this is the first time I'm using Regex.

CodePudding user response:

replace string to unique symbol and then split by it

to capture string use the pattern:

"by username .  \d ,\d{4}"

CodePudding user response:

As you can read here, regex is not the correct tool for parsing HTML.

In your situation I will use Google Apps Script in combination with a DOMParser library, as cheerio.

Example:

const content = getContent_('https://www.urbandictionary.com/define.php?term=nah');
const $ = Cheerio.load(content);
Logger.log($('.contributor').text());
  • Related