Using regex to eliminate emojis, such as 🔜 and more

Previously, I attempted to remove hashtags and comments from Twitter. The string I worked with looked like this:

@lien_ayy92 📡💯% Real 📡Avail▶#Jakarta #Bekasi 📡Excl/Incl 📡Expo▶6-7 Juli #Cirebon 📡Wajib DP💸 📡Cek BIO🔜 https://local.com/

My goal was to eliminate the icons and irrelevant text.

This is the code snippet from my previous attempt.

let clean = function (data) {
data = data.replace(/(?:https?|ftp):\/\/[\n\S]+|\B[@#]\w+\b|\b\w+[@#]\B|\B[^\w\s]{2,}\B|\b[a-zA-Z]{1,3}\b|[0-9]+|[$&+,:;=?@#|'<>.^*()%!-/]|\ud83d[\ude00-\ude4f]/g, '');
return data;
}
let stopwords = function (docs) {
  docs = clean(docs);
docs = docs.trim();
    docs = docs.toLowerCase();
docs = docs.split(' ');
  let wordsstop = ['about'];
let docs1 = new Array;
  var x =  0;
  for(let i = 0; i < docs.length; i++){
       if(wordsstop.indexOf(docs[i]) !== -1 || docs[i] == ""){

      }else{
      docs1[x] = docs[i]
      x++;
      }
  }
  return docs1;
}

console.log(stopwords('📡@lien_ayy92 📡💯% Real 📡Avail▶#Jakarta #Bekasi 📡Excl/Incl 📡Expo▶6-7 Juli #Cirebon 📡Wajib DP💸 📡Cek BIO🔜 https://local.com about data'));

I aim to achieve a result similar to this:

["real","juli","data"];

Answer â„–1

If you want to eliminate any items containing special characters, you can utilize the Array.prototype.filter method.

let clean = function (data) {
data = data.replace(/(?:https?|ftp):\/\/[\n\S]+|\B[@#]\w+\b|\b\w+[@#]\B|\B[^\w\s]{2,}\B|\b[a-zA-Z]{1,3}\b|[0-9]+|[$&+,:;=?@#|'<>.^*()%!-/]|\ud83d[\ude00-\ude4f]/g, '');
return data;
}
let stopwords = function (docs) {
  docs = clean(docs);
docs = docs.trim();
    docs = docs.toLowerCase();
docs = docs.split(' ');
  let wordsstop = ['about'];
let docs1 = new Array;
  var x =  0;
  for(let i = 0; i < docs.length; i++){
       if(wordsstop.indexOf(docs[i]) !== -1 || docs[i] == ""){

      }else{
      docs1[x] = docs[i]
      x++;
      }
  }
  
  // filtering process below
  var resultDocs = docs1.filter(function(data) {
    var tmp = data.replace(/[a-zA-Z$&+,:;=?@#|'<>.^*()%!-/]/g, '');
    if (tmp.length === 0) {
      return true;
    }
  });

  return resultDocs;

}

console.log(stopwords('📡@lien_ayy92 📡💯% Real 📡Avail▶#Jakarta #Bekasi 📡Excl/Incl 📡Expo▶6-7 Juli #Cirebon 📡Wajib DP💸 📡Cek BIO🔜 https://local.com about data'));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fetch operates based on the specified categoryId

Hey there, I'm currently in the process of learning JS and trying to fetch data from an API. I've successfully fetched all the work from api/works and displayed them in a div. Now, I'm looking to create 3 buttons that represent 3 categories ...

The alert function in the Ajax web method is malfunctioning

Every time I try to call the Ajax web method, I keep receiving a 'save error' message. However, the data is successfully saved to the database without any issues. I have checked for errors but couldn't find any. How can I display an alert sa ...

Testing asynchronous functions in React with jest and rtl: a step-by-step guide

I am currently testing my asynchronous submit function in my form using RTL and Jest, but I have encountered some errors during the process. This is actually my first time delving into code testing, so I find the testing procedures quite confusing. Below ...

The Material-ui Drawer element is failing to display its internal items

In my current project, I am building a practice e-commerce application utilizing React.js, @material-ui/core/Drawer, and Redux. I've encountered an issue where manually rendering items to the Drawer works fine, but utilizing a handleAddToCart function ...

Prevent selection of items in ng-select. Modifying the default item selection behavior in ng-select

In my code, I am utilizing an angular-multiselect component to upload a list of items and populate the [data] variable of the angular-multiselect. This component displays the list of data with checkboxes, allowing me to select all, search, and perform vari ...

Is it possible to display a value conditionally based on a condition from a Json object?

I'm looking to add a new feature that displays all the movies featuring Sean Connery in a button, but I'm stuck on how to implement it. Prettier 2.7.1 --parser babel </pre> Input: import React, { useState } from "react"; import ...

Bootstrap 3 Full-Width Responsive Image Overlapping

I have designed a grid layout with col-md-7 on the left side and col-md-5 on the right side. The images in the col-md-5 are responsive and have a full-width of col-md-12. <div class="container"> <div class="row"> <div class="col ...

Utilizing the Twitter API variable within ExpressJS while incorporating AngularJS

Using the "twit" Twitter package from GitHub, I am able to call the Twitter API and retrieve data that is logged in the console. However, I am unsure of how to pass this data to AngularJS in order to display the tweets on the front-end. T.get('search ...

Guide on Testing the Fetch Functionality of useEffect Using Jest in React

Can someone assist me with testing my useEffect Fetch using Jest in React? I've been struggling to make it work and tried various solutions without success. This is my first time using Jest, and I'm currently integrating it into my project. Belo ...

Error: Unrecognized error encountered while using Angularjs/Ionic: Property 'then' cannot be read as it is undefined

codes: js: angular.module('starter.services', ['ngResource']) .factory('GetMainMenu',['$http','$q','$cacheFactory',function($http,$q,$cacheFactory) { var methodStr = 'JSONP' ...

Trigger event upon variable modification

Currently, I am working on a school project that involves creating a website where users can listen to music together. I have implemented a button that allows the user to listen to the same song another user is currently playing at the right position. Howe ...

While attempting to deploy on Vercel, I encountered an error while constructing my Next.js project

While working on my Next login signup project, I encountered the following error: WagmiProviderNotFoundError: `useConfig` must be used within `WagmiProvider`. The documentation for this issue can be found <a href="https://wagmi.sh/react/api/WagmiProvide ...

Webpack has issues with loading HTML files

I encountered a 404 not found error while attempting to load the HTML page using webpack. Here are my configurations: Webpack.config.js: const path = require('path'); module.exports= { devServer: { // contentBase static : { ...

Struggling to parse the JSON blob that was returned when using express-handlebars in node.js? Let

I am in the process of learning node.js and following a tutorial that involves making requests to the Accuweather API and receiving JSON data. Almost there ... but struggling with displaying the data: index.js const express = require('express' ...

What is the most efficient way to implement hiding/showing elements, adding/removing classes, and optimizing code in jQuery?

Looking for a more elegant solution to toggle classes on a div when clicking a button? Current code logic: jQuery(document).ready(function($) { // Removing/adding classes to show/hide div elements on button click // More efficient w ...

Node causing CORS problem

As I work on setting up an app that enables cross-domain requests, I have been exploring various methods from a helpful post on How to enable cross-origin resource sharing (CORS) in the express.js framework on node.js Despite trying multiple approaches ou ...

IE users experiencing issues with parseInt conversion

It seems pretty simple at first glance, but I'm struggling with parsing a date string from a disabled field. I've tried splitting it by the forward slash and converting it to a number using parseInt, but nothing seems to work. I've spent hou ...

JavaScript enables users to store over 5 megabytes of data on their client devices

Is there a way to store more than 5mb in the client browser? I need this functionality across various browsers including Firefox, Chrome, Internet Explorer, Safari (iOS), and Windows Phone 8 Browser. Initially, localStorage seemed like a viable option as i ...

"Utilizing JSON data to implement custom time formatting on the y-axis with AmCharts

Looking to convert minutes to hh:mm:ss format in my JavaScript code var allDataTime = [{ date: new Date(2012, 0, 1), "col": "LONG CALL WAITING", "duration1": '720', "duration2": '57', "duration3": ...

Navigating through nested JSON objects using JavaScript

Trying to access and display a nested JSON object within the console. This is the JSON data: { "currentUser": { "image": { "png": "./images/avatars/image-juliusomo.png", "webp": "./images/avatars/image-juliusomo.webp" }, "us ...