Grabbing values not between quotation marks (regular expression) [duplicate] - regex

This question already has answers here:
Regex to pick characters outside of pair of quotes
(6 answers)
Closed 7 years ago.
I want to fetch the word outside a quotation for example if I have this text:
xxxx xxx OK xxxxx "xxx OK xxxx"
I want to fetch the "OK" outside the quotation which mean first one
I make this regular expression
[ ]OK[ ]
but it fetch the both. So how can I fetch only outside a quotation with regular expression?

You may use the combination of caturing group and the regex alternation operator.
"[^"]*"|( OK )
And now the group index 1 contain the <space>OR<space> which exists outside the double quoted part.
Code:
Matcher m = Pattern.compile("\"[^\"]*\"|( OK )").matcher(s);
while(m.find())
{
System.out.println(m.group(1));
}

Related

Regex for substring match [duplicate]

This question already has answers here:
Regex for string contains?
(5 answers)
Closed 7 months ago.
I have list of strings
03000_textbox (57447),
03990_textbox (57499),
03000_textnewbox (57447)
I want to use regex to capture 1st and 2nd elements of list.
Anything that contains substring textbox i.e.
03000_textbox (57447)
03990_textbox (57499)
Here is the regex you're looking for :
[0-9]+_textbox \([0-9]+\)
Live sample : https://regex101.com/r/2oiwcF/1
Don't forget to put a global (g) flag so you can get every match and loop into.

Extract all chars between parenthesis [duplicate]

This question already has answers here:
Regular Expression to get a string between parentheses in Javascript
(10 answers)
Closed 2 years ago.
I used
let regExp = /\(([^)]+)\)/;
to extract
(test(()))
from
aaaaa (test(())) bbbb
but I get only this
(test(()
How can I fix my regex ?
Don't use a negative character set, since parentheses (both ( and )) may appear inside the match you want. Greedily repeat instead, so that you match as much as possible, until the engine backtracks and finds the first ) from the right:
console.log(
'aaaaa (test(())) bbbb'
.match(/\(.*\)/)[0]
);
Keep in mind that this (and JS regex solutions in general) cannot guarantee balanced parentheses, at least not without additional post-processing/validation.

Regex find sting in the middle of two strings [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 5 years ago.
I want to get the time in the following line. I want to get the string
2017-07-07 08:30:00.065156
in
[ID] = 0,[Time] = 2017-07-07 08:30:00.065156,[access]
I tried this
(?<=[Time] = )(.*?)(?=,)
Where i want to get the string in-between the time tag and the first comma but this doesn't work.
[Time] inside a regex means a T, an i, an m, or an e, unless you escape your square brackets.
You can drop the reluctant quantifier if you use [^,]* in place of .*:
(?<=\[Time\] = )([^,]*)(?=,)

How to capture repeating groups in Regex (for C#) [duplicate]

This question already has answers here:
Get string between two strings in a string
(27 answers)
Closed 6 years ago.
I've to detect and extract from a string a repeating group of characters and list one part of each captured group.
Here is an example of string to parse: "za e eStartGood1Endds qStartGood2Endsds df"
My Regex is: ".*?(?::Start(.+)End.*?)+"
Expecting groups captured expected: Good1, Good2, etc
My Regex capture is wrong: it seems that (?::Start(.+) is considered as group to capture...
May I miss something?
Thanks!
This regex do the job :
/(?<=Start)(.+?)(?=End)/g
Why not use this pattern: \*{2}Start\*{2}(.*?)\*{2}End\*{2}
For this input string: za e e**Start**Good1**End**ds dq**Start**Good2**End**sds df, it captures Good1 and Good2.
You can play with it here: https://regex101.com/r/dG0dX6/2

What does it mean $1Z in regular expression [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 6 years ago.
I'm not familiar with regex, but I have the following string
d.$filter = d.$filter.replace(/TutoringSince le '(.+?)'/g, "TutoringSince ge $1Z");
Is anybody know what does it mean this Z char after $1 ?
$1 is a reference to the first group - in this case: (.+?)
Z is just a Z letter.
It replaces the captured text in the d.$filter, with TutoringSince ge, plus itself then adds a Z. I.e. the text
TutoringSince le 'whatever'
would turn into
TutoringSince ge whateverZ
"The captured text" would be anything inside the single quotes.