简体   繁体   中英

Finding pattern in data and structuring it

I've a sheet where I paste data from the website, when I paste, it look like this in sheet(Page 1 and Page 2):-

Here Color Code cells represent the data of one plot, like address , price , area and in address there is pincode

在此处输入图像描述

在此处输入图像描述

I am trying to make it structured like this if you take first two column block in P 1 in above image, I hope now it make some sense:-

  • I need to grab the Pincode from address

  • Address can be anywhere in columns, and below them will be there selling/renting details, like price, area etc

在此处输入图像描述

Don't know how to start, column has multiple property data which I want to structure

Here is the sheet link:- https://docs.google.com/spreadsheets/d/1M9YUR2NEc0IUvpwmzw1diMSMG9ukZw-269Rvg531WqY/edit#gid=0

Any suggestions?

Based on a fixed order of the data, starting at the address after that the price and after that the area

Delete unrelated data to avoid bugs

function findPatterns() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const ssname = ss.getSheetByName('Sheet1')
// ranges to process
  let columns = ['A24:A87', 'B24:B267', 'C24:C174']
  let res = []
  let arr = []
  columns.forEach(column => {
    let range = ssname.getRange(column).getValues().flat().filter(r => r)
    range.forEach(e => {
      let addres = e.match(/, CO \d/)
      let price = e.match(/^\$\d+(,\d+)?/gm)
      let area = e.match(/sqft|acres/)
      if (addres != null) {
        let pincode = e.match(/, CO (\d+)/).pop()
        arr.push(e, pincode)
      }
      if (price != null) {
        arr.push(e)
      }
      if (area != null) {
        arr.push(area[0])
        let num = e.match(/\d+(\.\d+)?/)
        if (num != null) {
          arr.push(num[0])
        } else {
          arr.push('')
        }
        res.push(arr)
        arr = []
      }
    })
  })
  res.forEach((el, idx) => {
    range = ssname.getRange('H' + (idx + 2) + ':L' + (idx + 2))
    range.setValues([el])
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM