Utilizing negative lookbehind regex in JavaScript

I am looking to identify all strings that begin with an @ symbol, unless they also contain other characters before the @. For instance, in @one @two and bla@three, I want to identify @one and @two, but not @three. This is for highlighting usernames in a chatroom.

These strings may appear anywhere within a sentence, whether at the beginning or in the middle.

I initially believed that (?![a-zA-Z])@[a-zA-Z]+ would suffice, but it still recognizes @three as well.

Answer №1

A regex look around is not necessary; a straightforward regex like this will suffice:

\B@\w+

View demo here

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

Error: The "require" function is not recognized in this context. (Unknown function) @ ng2-translate.ts:2

Encountering the following error: Uncaught ReferenceError: require is not defined(anonymous function) @ ng2-translate.ts:2 The issue arises from the line where I'm importing @anguar/http import {provide} from '@angular/core'; import {Http ...

What is the best method for swiftly saving a batch of parameters from an Excel spreadsheet - should I opt for a read or

After importing an excel file into R using read.csv(filename), I have extracted a portion of the data that appears as follows: [1] UserName, UserPassword, AppVersion, UserId, UUID, AppId, Latitude, Longitude [2] UserId, UUID ...

Why does the Node promise chain execute .then despite encountering an error?

When a promise chain encounters an error, why does it not execute .then unless the .then references an external method with a parameter? In this particular example, I intentionally throw an error in the promise chain. The first three .then methods do not ...

Incorporating JSON into a ColdFusion program

I have a website that showcases different views for registered and non-registered users. I am currently redesigning the product navigation to make it easier to manage by using JSON format. My website is built on Mura CMS with ColdFusion. Although what I ...

Unable to update game status using Discord.js setGame() function anymore

For the past 2 months, I've been developing my Discord bot using Discord.JS. However, I recently noticed that the bots I created are not displaying what they are playing as intended. Initially, everything was working fine, but now none of the 3 Discor ...

Tips for loading images dynamically (or lazily) as they come into the user's view with scrolling

Many modern websites, such as Facebook and Google Image Search, display images below the fold only when a user scrolls down the page enough to bring them into view (even though the page source code shows X number of <img> tags, they are not initially ...

Vue.JS enables the seamless addition of rows to a form on the fly

I am currently working on creating a dynamic form using Vue. The concept is that when the user clicks the add button, another row will appear for them to input data. However, I encountered an issue where initially only 1 row was set up, but when I added th ...

Searching for dynamic values within a string using Regex

Let's explore a sample string that has the potential to be dynamically constructed. {First String} <a href="{Variable Value}"><b>{Second Variable}</b></a> illustrative text <a href="http://www.example.com">sample conten ...

A guide to updating a particular row and sending parameters with jQuery and AJAX

I am utilizing a JSON response to dynamically display table content. Here is the code I am using to display row values: var rows = ''; for(var i=0; i<response.response.length; i++) { rows += '<tr><td class="country">&ap ...

Combining AngularJS and AngularFire: A guide to editing entries

In the $scope object, I have: $scope.current_account_key: This is the key obtained from my update modal $scope.current_account: It contains a name ($scope.current_account.name) and a description ($scope.current_account.description) for the account entry. ...

A step-by-step guide on generating a dynamic JSON file with JavaScript

I am in need of generating a JSON structure that follows this specific format: {"content": { "properties": { "area_id": "20", "origin": "3", "axis": "1", "x_start": "00", "x_end": "99", "y_start": "00", ...

Changing buffer from base64 to UTF-8 encoding in Node.js

My application imports messages from the Notes folder of Gmail using the imap npm module. When following the example on their GitHub page, all message contents are read into a buffer: stream.on('data', function(chunk) { count += chunk.len ...

Accessing factory in controller using AngularJS

Currently, I am utilizing the following link to integrate requirejs with angularjs: https://github.com/StarterSquad/startersquad.github.com/tree/master/examples/angularjs-requirejs-2 My question is regarding how to use a service function that is defined ...

List of suggestions for autocomplete in Angular

My autocomplete function is set up like this: chooseArtist: OperatorFunction<string, readonly string[]> = (text$: Observable<string>) => text$.pipe( debounceTime(200), distinctUntilChanged(), map((term: any) => term. ...

Javascript file containing prohibited characters disrupting form functionality when linked with Jquery

Having some trouble with these files - HTML form, PHP processor, and JavaScript. The browser is showing errors like U+12AF for illegal characters in the JavaScript file. Spent 1.5 hours on this already and feeling frustrated. --submit.js-- $(docume ...

Determine the duration in days between two datetimepicker selections using jQuery

I recently used a script to calculate the number of days between two datepicker inputs and it worked like a charm. $("#jqxDateTimeInput1").jqxDateTimeInput({ width: '250px', height: '25px', showTimeButton: true, formatS ...

The database does not get updated by an Ajax request without a page refresh

I'm currently in the process of developing a dashboard system and I've created a ToDo list for it. The main functionality of the system is to allow users to add, delete, and mark tasks as finished or unfinished. I am using codeIgniter for this p ...

Load data dynamically in JQM by fetching it with XMLHttpRequest on page load

When using pageinit to load a page, I am encountering an issue with XMLHttpRequest. I use it to send and receive requests to PHP programs on a Linux server using a RESTful API. The server side accepts the array I send and echoes back JSON data. Everything ...

Having issues with JavaScript and MySQL data retrieval following XMLHttp update to the database

After running the newNet.php file successfully creates a new entry and assigns it an auto-incremented netID. The next step is to retrieve this newly created ID and use it in the showActivities() function to display the record. Ideally, it should work like ...

Issue with the final transition of the last image in the Bootstrap carousel

I'm currently in the process of creating my own portfolio website. I've integrated a Carousel feature inspired by Bootstrap's example. However, I've noticed some glitches in the transitions between the first or second slides and the thi ...