Using regular expressions to extract data from a Solr query parameter FQ specifying a local tag

Currently, I am utilizing Ajax Solr for a development project. I am experimenting with the additive method in facet selection and successfully appending FQ values to breadcrumbs.

The issue at hand is that I only want the value to be displayed in the breadcrumbs.

For example:

 fq: "{!tag=places}places:\"usa\";  // Displaying Value in Breadcrumbs  "{!tag=false}places:"usa"

and

"{!tag=organisations}organisations:\"abcefg\"; // Displaying Value in Breadcrumbs "{!tag=organisations}organisations:"abcefg"

I specifically want only the value to be printed as shown below:

"{!tag=organisations}organisations:\"abcefg\"; // Displaying Value in Breadcrumbs "abcefg" "{!tag=places}places:\"usa\"; // Displaying Value in Breadcrumbs "usa"

How can I exclude "{!tag=organisations}organisations:" from the FQ data such that only the quoted values are returned?

I have attempted using:

fq[i].toString().replace('organisations', '').replace('{', '').replace('}', '').replace('!', '').replace('=', '').replace('false', '').replace('"', '').replace('"', '');

However, this method is not yielding the desired results of extracting quoted values.

If you have any suggestions on what regex pattern could be used in this scenario, please advise.

Answer №1

Check out this code snippet:

(?=.*\()(?<=(\\"))([\w]+)(?=\\")|(?<=")([\w]+)(?="))

To see how it works, try it on your test scenario 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

Tips on effectively centering a wide div

After much experimentation, this is what I came up with: (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en ...

serving files using express.static

I have set up express.static to serve multiple static files: app.use("/assets", express.static(process.cwd() + "/build/assets")); Most of the time, it works as expected. However, in certain cases (especially when downloading many files at once), some fil ...

What are some strategies for stopping a form from redirecting me while utilizing ReactJS and ExpressJS?

Recently, I created a form that redirects to the route /repair upon submission with an action of /repair. However, I would prefer to keep it as a Single Page Application (SPA) where after submitting the form, the fields are cleared, and a simple message l ...

Revising HTML content when Angular array is modified

I have a code snippet below where I am updating the value of an object in the first item of an array. However, I'm struggling to find a way to "refresh" the HTML view so that the changes are immediately reflected on the browser. var dataArr ...

What causes the undefined value of "this" in the Vue Composition API setup function?

A Vue component I've created is using v3's composition API: <template> <input type="checkbox" v-model="playing" id="playing" @input="$emit('play', $event.target.value)" /> <labe ...

A single, powerful JavaScript function for validating input fields on web forms

Looking to streamline my code by creating a function that checks if an input field is empty before sending the data to Php via Ajax. The function should return true or false and display an error message if needed. However, I'm facing an issue when dea ...

When downloading text using Angular, the file may not display new line characters correctly when opened in Notepad

When downloading text data as a .txt file in my Angular application using JavaScript code, I encountered an issue. Below is the code snippet: function download_text_as_file(data: string) { var element = document.createElement('a') eleme ...

Introducing the innovative system that enhances the functionality of jQuery Ajax

Whenever a button is clicked, it triggers an ajax call. The button includes a variable that needs to be passed along with the ajax request. Once the data is returned using .done(), I am looking for a way to dynamically connect multiple other functions (pot ...

Tips for displaying a specific PDF file using the selected programming language

As a newcomer to react.js, I have a question regarding my system which allows the user to select the default language. If the chosen language is French, there is a specific URL that needs to be included in the Iframe path. For Spanish, it's a specific ...

Issues with my transpiled and typed TypeScript npm module: How can I effectively use it in a TypeScript project?

I'm trying to experiment with TypeScript. Recently, I created a simple "hello world" TypeScript module and shared it on npm. It's very basic, just has a default export: export default function hello(target: string = 'World'): void { ...

The input field text does not get highlighted when clicked on in Firefox while using AJAX and jQuery

Each time I click on an edit box, the input field (text) does not stay selected or focus back in that input field. Keep in mind that this editbox is located within a table. This issue only occurs in Firefox; it works fine in Google Chrome. Below is the s ...

Perform a function dynamically once a specific textfield is filled and continuously while filling another textfield

Imagine we have two text fields - one for a first name and one for a surname. As I type in the surname field after already filling out the first name, a function called sug() should provide suggestions or perform some action each time I add another letter ...

Challenges with Vuex and updating arrays using axios

I am currently facing a challenge with VueJS Vuex and Axios: The issue arises when I retrieve an array with Axios and loop through it to populate its children this way: "Rubriques" has many self-relations, so one rubrique can have multiple child rubriques ...

What is the operational mechanism behind drag and drop page builders?

I am currently delving into my inaugural MERN project, where the functionality requires specific components (such as a checkbox to-do list, images, text, etc...) that empower users to construct various pages, larger multi-checkbox aggregation lists, and be ...

Emulating a button press on the login screen

I have been attempting to utilize jQuery to simulate a button click on a login page. Interestingly, the conventional JavaScript method functions as expected: document.getElementById('loginButton').click(); However, the same action using jQuery ...

Executing a closure within a promise's callback

Currently, I am working on implementing a queue system for a web application in order to locally store failed HTTP requests for later re-execution. After reading Mozilla's documentation on closures in loops, I decided to create inner closures. When ...

Ideas for utilizing jQuery to extract data from CSS files

Hey there, I'm facing an issue on my HTML page where I have jQuery included. In my CSS file, I have quite a lot of lines and I'm trying to figure out how to read all styles for a specific element from the external CSS file rather than the inline ...

Creating a web application with nested JSON objects

Currently, my goal is to develop a Web App (which will later become a hybrid app via Phonegap) with Wordpress as the backend. The information will be dynamically loaded through a JSON API. However, I am facing a roadblock at the initial stage. My aim is ...

Stop the automatic refreshing of the webpage when searching using Ajax

I have a script that automatically reloads the content of a page every few seconds. function() { $('#lista').show().load('listaupdate.php').fadeIn("slow");}, 3000); The problem is, there is a search form on the page. How can I prevent ...

Mastering the art of utilizing clearInterval effectively

This reset button needs to clear/reset the timer. The issue is that when the user presses the start button more than once, it sets two timers - one from the previous start and one from the current start. I will be using clearInterval to solve this problem ...