Extracting precise information from a text

I need to parse a lengthy text in order to extract data based on a specific pattern.

Pattern:

(placeholder) placeholder (placeholder|placeholder)

for instance

(Location X) 231 (-5|10) or (Town Y) 789 (231|-15)

There are numerous occurrences of these phrases in my text and I aim to store each one in an array.

Answer №1

Here is a regular expression that can help you achieve your goal:

const input = 'Some random text (City) 479 (147|-20) Some random text';

const result = /\(\s*([^)]*)\s*\)\s*([^(]*)\s*\(\s*([^|]*)\s*\|\s*([^)]*)\s*\)/g.exec(input);

console.log(result);

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

What is the best way to organize objects by their respective dates?

I am retrieving data from a database and I would like to organize the response by date. I need some assistance in grouping my data by date. Below is an example of the object I have: var DATA = [{ "foodId": "59031fdcd78c55b7ffda17fc", "qty" ...

Scroll the div until it reaches the top of the page, then make it fixed in place

Let's dive right in: The code I am working with is as follows: <div id="keep_up"> <div id="thread_menu"> <div id="new_thread"> </div> </div> </div> And here is my CSS: #keep_up { po ...

Opting for Mysql over MongoDB as the provider in Next.js with Next-auth

Exploring the Next.js framework for the first time, I've dived into using Next-auth to handle sign-up/login functionality based on the provided documentation. My experience so far has been smooth, especially with the MongoDB provider as recommended i ...

Excessive data flooding the console through Socket.io until the Payload reaches an unsustainable size

This snippet of code forms part of a chat application developed using React Native, functioning through a socket.io server. const Message = ({text, isSent}) => { return ( <View style={[styles.messageContainer, isSent ? styles.sentMessage : styl ...

How can I retrieve file input values in angularjs?

Currently, I am working on a simple application in AngularJS with the Slim framework. This application includes a form where users can input data such as their name, categories, currency, and an image file. While I am able to successfully retrieve data fro ...

Retrieve values from a nested object using a variable in AngularJS

obj { val1 { nestedval {} } val2 { nestedval {} } } I'm having trouble accessing the nested value and assigning either val1 or val2 as a variable. I've been trying: var getVal = obj.varible.nestedval but it's not working f ...

Requesting information asynchronously returns a positive response

I wrote the following code: if (venue_exists(instagramUserID)){ alert('A'); }else { alert('C'); } function venue_exists(instagramUserID) { $.get( "/venues/" + instagramUserID, function( ...

What steps can I take to successfully utilize $index named variables in Angular?

There is a div element in my HTML file with the following code: <div ng-repeat="loss in Model.plDetails track by $index"> <div class="col-sm-2"> <div class="input-group"> <input type="text" class="form-cont ...

Tips for resolving the issue with TypeError: arr[Symbol.iterator] not being a function in my React application

I am facing an issue while trying to follow this tutorial. Although I have diligently followed the code provided, I seem to be encountering an error that the tutorial creator did not experience. This problem arose at the 2:09:30 mark in the tutorial. Afte ...

Getting command line argument parameters in React can be achieved by utilizing the `process.argv`

Is there a way to retrieve command line argument parameters in React? I currently have a React codebase that is utilizing Webpack. When running the following commands - npm run build -- --configuration=dev or npm run build -- --configuration=qa I need t ...

Encountering Issue with Ionic Js After Upgrading Node to Version 4.1.1 on Windows Platform

Recently, I updated Node to version 4.1.1 and now I'm encountering an issue with Gulp: Error: libsass bindings not found. Have you tried reinstalling node-sass? I've attempted various solutions to no avail, including: Removing node_modules an ...

What is the most effective way to showcase dynamic labels and their values in a pie chart using chart.js?

Here is my current Pie chart https://i.sstatic.net/ABwVv.png, however, I am aiming for this type of chart https://i.sstatic.net/TdJ21.png I am trying to dynamically display labels and label values in a pie chart using Chart.js. The issue with my code ...

Chrome and Firefox: Images cling together

I've encountered an issue with my recently launched website. Some images in a grid appear to be stuck together, but this problem only occurs in Firefox and Chrome browsers. Oddly enough, zooming in to around 110% then back to 100% seems to temporarily ...

Here is how you can trigger an event when clicking on a live chat using JavaScript

Looking to track user clicks on Livechat within my website, I encountered a problem with Subiz (another Livechat tool) even after receiving solution for Purechat from Stack Overflow. For reference, here is the previous solution for Purechat: How to raise ...

Compatibility problem arising from the versions of ember-precompile, ember.js, and handlebars.js

Having trouble reading the precompiled templates in my HTML due to compatibility issues between ember-precompile, ember.js, and handlebars.js. My code looks like this: Includes the following files. <script src="../js/libs/jquery-1.10.2.js"></sc ...

Prevent deletion of already uploaded images in Blueimp by disabling the delete button

After using the blueimp upload script to upload files, I noticed that the file information is saved in a data table along with the upload timestamp. However, when I go to edit the form, the files reappear. The simple task I want to achieve is disabling th ...

Show the predetermined information in the dropdown menu

Objective: I want the modal to display a dropdown list with preselected data based on the selected row. The dropdown list should show the user's month data, for example, if Josef's month value is 2, 'Feb' should be the first option di ...

Experiencing variations in value with the MUI date picker

I encountered an issue with the Mui 5 date picker. When I change the date using the calendar, I get the expected result. For example, if I select the 26th, I get the following timestamp: "2022-01-26T09:16:10.000Z". However, when I directly edit ...

What strategies can be used to prevent state mutations?

I am facing mutability for the first time. My state items consist of an object with keys like id, and using allIds I am trying to update specific id items with a new date. However, all items are being changed simultaneously, which I believe is due to mut ...

Is it possible to utilize the defineProperty accessor in JavaScript to modify the .length property of an array?

I am interested in setting an accessor on an array's length using Object.defineProperty() for academic purposes. This would allow me to notify for size changes dynamically. While I am familiar with ES6 object observe and watch.js, I prefer exploring ...