What is wrong with this RegExp? [duplicate] - javascript

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Closed 6 years ago.
I have this string
§serverUrl§/image/?url=§externalMedia.data.image§
and I want to match only the string inside the § character.
(serverUrl and externalMedia.data.image).
I'm using this pattern :
/§.+§/g
but it catches also the characheters between the two groups.
Any help would be appreciate. Thanks

You will have to make it lazy using ? like this §.+?§
Regex101 Demo

Related

Javascript - replace pattern but keep alphabets [duplicate]

This question already has answers here:
How can I replace a regex substring match in Javascript?
(4 answers)
How to replace captured groups only?
(7 answers)
Closed 3 years ago.
I was wondering, what is the best way to implement the following case:
vm.elasticQuery = userQuery.replace(/~='[a-zA-Z]+'/g,':*[a-zA-Z]+*')
In other words, I would like to replace every pattern that looks like this ~='SomeLetters' to a pattern that looks like this :*SomeLetters*. Take into account that I do not want to remove/change the alphabets but only the outside.
Your help is appriciated.

Regex Unexpected ^ and character match [duplicate]

This question already has answers here:
Javascript: Split a string into array matching parameters
(3 answers)
Closed 4 years ago.
I have this regular expression that tokenizes calculator input strings like 12+3.4x5 to 12,+,3.4,x,5
The regular expression used is
\d+\.?\d+|[\+-÷x]
I get an unexpected match with ^ and letters.
Regex solution, although there's probably a cleaner way of writing this if someone could point it out?
(\d+\.?\d+|\d+|(\+|-|÷|x))

jQuery replacing only one character [duplicate]

This question already has answers here:
How do I replace all occurrences of a string in JavaScript?
(78 answers)
Closed 5 years ago.
jQuery:
console.log("'Wild.jpg'".replace("'", ""));
Output:
Wild.jpg'
How can I resolve this and make the output as Wild.jpg?
You should use RegEx with the g modifier instead of an ordinary string replacement:
console.log("'Wild.jpg'".replace(/'/g, ""));
Try this.. here we gave /g to replace all.
console.log("'Wild.jpg'".replace(/'/g, ""));

REGEX javascript - find two chars set [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 5 years ago.
i've to find the sequence of chars ,. inside a json file for example: ":0,.0}},{", so what is the best fitted regex string for it?
i tried /(,.){1,}/g but it doesn't work well.
It's because . is a special character.
const r = /(?:,\.)+/g
console.log('abc,.,.,.def'.match(r)) //[",.,.,."]
you need to escape the .:
/,\./g

What are the ways to search for several alternate characters without creating a capturing group [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
Suppose I have a task to search for words that start with either a or b, for example all or bll words. I know I can use grouping and or operator like this:
(a|b)ll
But this creates a capturing group. Are there any other options?
How about using square brackets instead of parens like: [ab]ll ?

Categories

Resources