Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 14 days ago.
The community is reviewing whether to reopen this question as of 14 days ago.
Improve this question
How do I check if part of string is valid JS syntax? I heard that acorn.parse returns true or false if given string is valid JS syntax or not. However, what if only part of string is valid JS syntax code. How should I aproach this?
let str = "This string contains words and valid JS syntax. I should extract only the part which is the syntax. function foo(){}"
extractValidSyntax(str) // "function foo() {}"
Related
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 3 years ago.
Improve this question
How to convert string to valid json ?
const string = "[{foo:bar,key:value},{foo:bar,key:value}]";
So that i can parse it using JSON.parse(string).
Note that : i cant manually put (") to every keys and values. I am stack here that's why i am on stackoverflow.
Using regex to replace any words or numbers will work for the json you have supplied, it will not however work if you have mixed value and "value" properties.
var text = "[{foo:bar,key:value},{foo:bar,key:value}]";
console.log(JSON.parse(text.replace(/(\w+|\d+)+/g, '"$1"')));
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 years ago.
Improve this question
I have a simple Regex to match 'der' - /der/g
I need the context around the match. Is there any way to build the regex that way? Thank you in advance.
If you want to match the context plus the search string, simply add the optional range before and after the searched string: .{0,5}der.{0,5}
If you want to get the context only, you have to fetch it separately: (.{0,5})der(.{0,5})
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
The below code is full of string. I want to select cbUserURLs array variable.
var someurl =new Array('a','b');
var cbUserURLs =new Array('url1','url2',...);
.. //some code
What is the regular expression should I use here?
You just need use cbUserURLs.*\); if what you want is
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to make a caching mechanism. I want to drop the last digit of the latitude and longitude for example :
look below how to make request. important things are the "lat" and "lon" values. There must be four digits after the full stop (also known as a period).
3 Request /v1/x/y/?lat=40.12225&lon=2.13422&radius=1&key=abc
caching look up: /v1/x/y/?lat=40.1222&lon=2.1342&radius=1&key=abc-> no match (look at lat=40.1222&lon=2.1342)
You can use the following regex to trim your strings to the correct format:
/(?:lat|lon)(=\d+\.\d{4})\d*/g then you replace with $1
Example:
var s = "/v1/x/y/?lat=40.12323&lon=2.13421&radius=1&key=abc"
s.replace(/((?:lat|lon)=\d+\.\d{4})\d*/g,"$1");
Output:
/v1/x/y/?lat=40.1232&lon=2.1342&radius=1&key=abc
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 8 years ago.
Improve this question
I want the regular expression to extract the &[1], &[2},&[3],&[4] values from the following string, with comma delimited.
var str = "Sum({[Account].&[1]+[Account].&[2]+[Account].&[3]+[Account].&[4]})";
Thanks for your help
(&\[\d+\]) Seperates them in to groups, you have to delimit them with commas yourself but that's not a big problem.. :P
Btw.: This is a great test for regex testing purposes http://rubular.com/r/0kLKf1gTaD