Using Javascript Regex to conceal non-ASCII characters in strings

I'm currently working on masking strings using JavaScript regex. However, I've encountered an issue with non-ascii characters. How would you suggest resolving this problem?

Below is the code I've been using:

var name = "Üsüaüü Bxbdüxüqzx Aqwexü"
var regex = /(?<![\p{L}\p{Mn}\p{Nd}_])(\p{L})(\p{L}*)\b/ug
console.log(name.replace(regex, (_, first, middle, last) => `${first}${'*'.repeat(middle.length)}`))

Expected output:

Ü***** B********* A*****

Appreciate any input on solving this issue.

Answer №1

Just swap out this particular line

var regex = /(?<![\p{L}\p{Mn}\p{Nd}_])(\p{L})(\p{L}*)\b/ug

With

var regex = /(?<![\p{L}\p{Mn}\p{Nd}_])(\p{L})(\p{L}*)/ug

Trust this resolves your issue

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

Modifying an image with jQuery

Why won't this image change? Below is the relevant HTML, CSS, and jQuery code. HTML <nav id="desktop-nav"> <div class="logo"> <a href="#"></a> </div> <div> ... </div> ... CSS nav#desktop-nav . ...

Unable to make changes to a file authored by a different user within Firestore using Vue.js / Firestore

I appreciate any assistance in advance, as this issue has been causing me a lot of frustration! Currently, I am adhering to the firestore data model where users are able to create their own documents associated with their userID. This ensures that users c ...

MDL Tab loading Problem

When visiting my website at this link, which is powered by MDL from Google, there is a troublesome issue that occurs. The #harule tab briefly appears before disappearing. This tab should actually be hidden on the page until a user clicks on the harule tab ...

Display or conceal a div element depending on the value selected in Vue.js

I have a Vue.js dropdown and I would like to show or hide my div based on the selected value in the dropdown. The current code is only working for one ID, but I want it to work for all IDs. I want to toggle the visibility of my div based on the option&apos ...

What is the best way to add 1 to a number every second with javascript?

My code seems to be functioning correctly, but I'm having trouble setting the delay and stopping the increment after a certain interval. Can someone please assist me with this? Javascript: $(document).ready(function() { var number = parseInt($(& ...

Guide to integrating jssor into an AngularJS application

Struggling to integrate jssor with angularjs, it seems to be failing because jssor is being initialized before angularjs, causing the ng-repeat elements to not resolve correctly. <div id="slider1_container"> <div u="slides"> <!-- Th ...

Incorporate issues into the VeeValidate error collection using the parent component, then monitor them from the child components

Is there a way to implement data transfer from a parent component to a child component for error handling? Specifically, how can I add data to the errors bag from the parent component and then listen to a specific error in the child component to display so ...

Optimize my webpage for a specific location

While developing a game website, I am interested in learning how to enable only specific parts of my website to function while disabling the rest. How can this be achieved? ...

Tips for crafting effective error messages to communicate with users

One of the biggest challenges I face is crafting clear error messages for clients in case of errors. A typical scenario involves using Axios and a third-party API to fetch data, requiring appropriate error handling for both. Axios' error handling doc ...

Javascript functions correctly when the HTML file is opened locally, however, it encounters issues when accessed through an http-server

My HTML file includes an embedded web widget from tradingview.com with the following code: <!-- TradingView Widget BEGIN --> <span id="tradingview-copyright"><a ref="nofollow noopener" target="_blank" href="http://www.tradingview.com" style ...

Using the value from the Vuex state to set the initial value for a different parameter

I am facing an issue with utilizing an array of objects in my Vuex state to set a default value for another parameter, specifically for mainAccount: For instance: const store = new Vuex.Store({ state: { AccountNums: [ { label: 'M ...

Issues with implementing KendoUI's datepicker in conjunction with Angular

My index.html file contains the following imports: <script src="content/js/angular.js"></script> <link href="content/js/kendo.common-material.min.css" rel="stylesheet" /> <link href="content/js/kendo.material.min.css" rel="styleshe ...

Creating an accordion feature within an ng-repeat using AngularJS based on user clicks

When I click on the span with ng-click="click_subcat(opp.ct_nm);, the content is loaded within the <span ng-click="click_pdms(opp.sbct_nm);" style="color:white;cursor:pointer">{{opp.sbct_nm}}</span>. The issue arises when I click on that span a ...

Adding a fresh element to an array in a mongoDB document

After researching various SO posts, I have come across different methods to achieve this task. Hence, I am curious to know which approach is considered the most preferable. Since I am instructing students, it is important for me to teach them best practice ...

The live() function is causing issues with my ajax request

Within my webpage, I have a link with an onclick() event that should display a div containing a date input text named "datepicker0", followed by another div with the id of "bContent". I've included the script below to implement a date filter on the d ...

If the HTML DOM is unresponsive on the initial click of an element, consider using JavaScript to troubleshoot the issue

I recently encountered an issue while working on a school webpage. I implemented some JavaScript code to show and hide certain elements upon click, but ran into trouble with external CSS properties not being recognized by the script. function grabClassNam ...

Closing tag in jQuery

In my script, I am using a div tag within the jquery code. However, whenever the div tag appears in the jquery code, it automatically closes the script tag and breaks the jquery code. For example, consider the following code: <script>var b = 25;var ...

Create a lockscreen feature in AngularJS that becomes active after a period of inactivity

I am looking to integrate a lockscreen feature into my app using Angular.js. This lockscreen will consist of a route and an HTML template containing a form that prompts the user to re-enter their password in order to keep their session active. The purpose ...

React is failing to display identical values for each item being mapped in the same sequence

I have implemented some standard mapping logic. {MEMBERSHIPS.map((mItem, index) => ( <TableCell className="text-uppercase text-center" colSpan={2} padding="dense" ...

`npm run build` in Ubuntu does not detect any environment variables in process.env

Currently in the process of deploying a VueJS project. I have a file that contains API URLs where process.env is used. In production, if API_URL is defined, I can use localhost on my development server and switch to API_URL in production. const apiRoot = p ...