JavaScript get text between round brackets ignoring inside brakets [duplicate] - javascript

This question already has answers here:
Regular expression to match balanced parentheses
(21 answers)
How can I match nested brackets using regex?
(4 answers)
Closed 4 years ago.
I want to get the text inside this bracket using regexp
var str = "func(arg(), arg)()";
str.match(/regex/)[0]; // Results "arg(), arg"

Related

need some changes in spliting - Javascript [duplicate]

This question already has answers here:
Limiting the times that .split() splits, rather than truncating the resulting array
(8 answers)
javascript split string by space, but ignore space in quotes (notice not to split by the colon too)
(3 answers)
Split a string by whitespace, keeping quoted segments, allowing escaped quotes
(4 answers)
Regex for splitting a string using space when not surrounded by single or double quotes
(16 answers)
Javascript split by spaces but not those in quotes
(3 answers)
Closed 8 days ago.
"/ban Hitesh27 "Disrespect so banned".split(" ")
exepected was [ "/ban", "Hitesh27", "Disrespect so banned"]
Result was [ "/ban", "Hitesh27", "Disrespect", "so", "banned"]
i see why the result was like that but i don't know how to fix it yet

Handling special characters in Java script to enclose them in Square Brackets? [duplicate]

This question already has answers here:
Wrap Numbers in Brackets using javascript .replace regex
(1 answer)
Check for special characters in string
(12 answers)
Closed 2 years ago.
I am trying to write a Java Script function that should enclose all the special characters in the given String in a bracket like following -
Input ===> Output
123##$, ====> 123[#][#][$][,]
Changing All the special characters to certain String [ _ in this case] is easy -
string = string.replace(/[^a-zA-Z0-9]/g,'_');

Split by word not contained in parentheses [duplicate]

This question already has answers here:
How to split by commas that are not within parentheses?
(6 answers)
How to split string while ignoring portion in parentheses?
(5 answers)
Closed 3 years ago.
Here is the my string
var string = 'Title:(India OR America) OR Keyword:(Education)';
After splitting with "OR" it is showing
["Title:(India", "America)", "Keyword:(Education)"]
But what I need is the below one.
["Title:(India OR America)", "Keyword:(Education)"]
Could anyone please help on how to split the string to get the required result.
To achieve this you'll need to use a negative lookahead to only find the OR string where it's not contained in parentheses. Try this:
var input = 'Title:(India OR America) OR Keyword:(Education)';
var output = input.split(/(?!\(.*)\s?OR\s?(?![^(]*?\))/g);
console.log(output);

Regex to get string between two specific tags [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
What special characters must be escaped in regular expressions?
(13 answers)
Closed 4 years ago.
I have a string like:
[device]Some device[/device]
I am trying to write regex that will return only "Some device".
/[device](.*?)[/device]/i.exec(str) // doesn't work
/[device](.*)[\/device]/g.exec(text) // doesn't work
I am not sure how to extract it?
I already tried solution from Regular Expression to get a string between two strings in Javascript and it doesn't work for string like [][/]
[device]Some device[/device]
return
evice]Some device[/device] and all other strings.

Javascript string split with regex multiple conditions [duplicate]

This question already has answers here:
Javascript: Split a string by comma, except inside parentheses
(7 answers)
Regex split string by spaces taking into account nested brackets
(2 answers)
Closed 5 years ago.
I'm trying to split string
x#x,a,b,c,d(some(other,arg2),p)#yyy into array
['x#x','a','b','c','d(some(other,arg2),p)#yyy'].
The problem i faced is that i cannot split just comma /\,/g since members that contains already commas would split also. Any ideas?

Categories

Resources