Is there a way to eliminate curly braces from JSON strings with a regular expression?

Hello, I am working with a JSON file and I need to manipulate the content of the chapters array. Specifically, I want to remove the curly braces from inside the strings but only if they contain more than three words (two spaces). Is it achievable using Regular Expressions?

 {
    "abbrev": "gn",
    "name": "Genesis",
    "chapters": [
        [
            "And the earth was without form, and void; and darkness {was} upon the face of the deep. And the Spirit of God moved upon the face of the waters.",
            "And God said, Let there be light: and there was light.",
            "And God saw the light, that {it was} good: and God divided the light from the darkness. {the light from...: Heb. between the light and between the darkness}",
            "And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day. {And the evening...: Heb. And the evening was, and the morning was etc.}",
            "And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters. {firmament: Heb. expansion}"
        ]
 ] }

I have attempted to use negative look ahead in my Regular Expression but with unsatisfactory results. If removing curly braces is not feasible through Regular Expressions, what would be an alternative solution using JavaScript?

Answer №1

There's no reason why you couldn't tackle this problem with the help of two regular expressions:

let regex1 = /{[^{}]+[ ][^{}]+[ ][^{}]+}/g;
let regex2 = /[{}]/g;

let inputString = ...;
inputString = inputString.replace(regex1, '');
inputString = inputString.replace(regex2, '');

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

Guide on verifying Unicode input in JavaScript?

I am looking to create a form where the user can only input Khmer characters (Unicode characters) and display an alert if they input anything else. Khmer Name: <input type="text" class="namekh" name="namekh"> To achieve this, here is a snippet of m ...

Tips for retrieving the selected option from a dropdown list using ReactJS

Currently, I am attempting to extract the value of a dropdown menu structured like this: <ul className="tabs" data-component={true}> <li> <section className="sort-list" data-component={true}> <select value={0} class ...

history.js - failure to save the first page in browsing history

I have implemented the history.js library to enable backward and forward browser navigation on an AJAX products page triggered by clicking on product categories. While I have managed to get this functionality working smoothly, I am facing a particular iss ...

Alerting old session data following an AJAX request

After making an AJAX call that updates a $_SESSION variable, my <script> is supposed to echo out the new variable. However, it keeps alerting the old data even though the data is reaching the .php page and being stored in the session. I've attem ...

Turn off the authentication middleware for a particular HTTP method on a specific endpoint

Currently, I am using Express/Node and have developed authentication middleware to validate JWT on each request. My requirement is to disable this middleware for a specific route (POST '/api/user/') while keeping it active for another route (GET ...

The error message "Unable to retrieve property 'commands' of undefined (discord.js)" indicates that the specified property is not defined

As I try to incorporate / commands into my Discord bot, I encounter a persistent error: An issue arises: Cannot read property 'commands' of undefined Below is my main.js file and the problematic segment causing the error: Troublesome Segment c ...

Strategies for transferring data from index.html to component.ts in Angular 4

Greetings, as a newcomer to Angular, I am seeking advice on how to link my Index.html file to component.ts. Please review the code snippet below where I have created a function called scannerOutput in my Angular index.html file which is functioning properl ...

What is the most effective method for sorting through vast amounts of data with Javascript, React, and Redux?

Currently, I am working with a minimum JSON data set of 90k [...] and utilizing the .filter method. Everything is functioning correctly without any issues, however, from a performance standpoint, I am curious about potential improvements. Any suggestions o ...

Key to Perform Right Click

Hey, I could use a little advice window.addEventListener('keyup', function (event) { if (document.activeElement && document.activeElement.tagName === 'INPUT') { return; } switch (String.fromCharCode(event.keyCode ...

Tips for implementing a conditional statement within an export default clause

I am completely new to web programming and I'm attempting to create a question-answer feature using Vue.js. export default { // Trying to implement an if statement (if character == "Past", then do these steps) "steps": [ { ...

Upon upgrading kombu, an issue has arisen where the task_id is not JSON serializable

After upgrading, I encountered an ERROR EncodeError(TypeError('6JQAKHNMG9 is not JSON serializable',),). The following packages were successfully installed: amqp-2.1.4 billiard-3.5.0.2 celery-4.0.2 kombu-4.0.2 pytz-2017.2 (These were i ...

Learn the process of including authorization header in Android using Volley library for GET requests

how to send Authorization header using volley library in android for GET method please help me thank you public void token(){ SharedPreferences userInfo = getActivity().getSharedPreferences(DataManager.SharedPreferences, Context.MODE_PRIVATE); S ...

Transforming Child_process.spawn's "Promise" syntax into "async/await" syntax.---Here's how you can convert the syntax of Child_process.spawn from using

Trying to wrap my head around the async/await syntax, I have come accross a code snippet that intrigued me. The following is the Promise-based version of the code: function callToolsPromise(req) { return new Promise((resolve, reject) => { l ...

Quickly Share Documents within a Folder

I currently have a server set up with the following file structure: - index.js /client -index.html -about.html -signup.html -style.css Within the index.js file, I have implemented an express server. When the user navigates to /, it should display the ...

When it comes to MongoDB aggregation, the order of indexes is not taken into consideration

To retrieve the 100 latest documents from a MongoDB collection, where each document is a combination of multiple documents with a similar field (in this case timestamp), I have implemented a series of queries using Node.js: return q.ninvoke(collec ...

Generating a multidimensional array using a list of JSON objects

My task involves working with a JSON feed that contains a list of objects, each with its own id and idParent. The objects with an idParent of null are considered the base parent elements. I want to create a multidimensional array resembling a tree view, ke ...

Pattern for handling errors in an efficient and streamlined manner

Currently, I am exploring the use of Express for developing a basic JSON API. However, I have concerns about how to effectively manage input parameter validation and error handling in my project. Errors can occur during both the validation process and when ...

Ways to transfer a variable from a Node.js script to a JavaScript file on the client side

Seeking guidance on how to transfer the "myBlogs" variable from my Node.js file ("server.js") to a frontend JavaScript file ("blogs.js"). I intend to utilize this variable in the JS file to iterate through the array it contains, generating a template for e ...

Is it possible to interchange image src once the page has finished loading?

My current dilemma involves an image that is being inserted into my website through a third-party script: <img src="https://example1.com/image1.png" id="image1"> What I am trying to achieve is replacing this initial image with another one, like so: ...

Ways to convert a jQuery object into HTML that can be utilized?

When running the code below, an alert message of "object Object" is displayed: var shipImgs = $("#div").children(); alert(shipImgs); The container with id "div" includes a total of 4 children (image tags). <div id="div"> <img src="/imgs/spa ...