Skip to content
Advertisement

Tag: string

How could I replace repeated complex strings in javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago. Improve this question For example, the input would be: @[facts.::ip](facts.::ip) = “127.0.0.1” AND @[facts.::os](facts.::os) = “ubuntu” I would like to transform that into:

How to replace square brackets and set dot before replacement?

Good day. I wish to replace square brackets inside string and set dot before replacement. For example, Current string position[0].type i need transform to next one position.0.type I have tried making it by this rule ‘position[0].type’.replace(/[[]]/g, ”) as expected, will removed only brackets, how i can set needed dot? Thanks. Answer You can use The [[].]+ regex matches one or

How to encode string in javaScript

I am doing an exercise, the task is: I need to write a function which takes an argument a string and returns encoded string, for example: aaabbcccc -> should return 3a2b4c. I wrote the function, I created an object where I have all characters counted but I don’t know how to return value and key converted into the string. Here

JavaScript: Search string from position

JavaScript has two useful methods, both which nearly do what I need. String.prototype.indexOf() will search for a substring and return its position. It has an optional position parameter which is the starting point of the search, so you can easily find the next one. String.prototype.search() will search a string using a regular expression and return its position. However, as far

Advice on how to resolve an issue with extracting only numbers from a string using JavaScript

I’m new to stackoverflow and would appreciate some advice to help me solve this problem. I have two strings that I want to extract numbers from String 1 = “12.3,Name1,3,4,Name2,35,Name3” returns [12.3,3,4,35] Which is the required result. String 2 = “12.3,22,Q” returns [12.322] Which is the incorrect result, It should be [12.3,22] I have commented on my code with the

Regex expression not returning entire term

The intention of the regex is to capture substrings wrapped between twin expressions in parentheses, kinda like html tags. For example: And here’s my code Can anyone tell me why this doesn’t capture the entire thing? Answer The characters () are special in a regexp and must be escaped with a if you want to match them literally. And

Advertisement