What does this regular expression mean - '(?<word'? [duplicate] - regex

This question already has answers here:
Reference - What does this regex mean?
(1 answer)
Can I use named groups in a Perl regex to get the results in a hash?
(5 answers)
Closed 5 years ago.
I found this regular expression in Raisin code:
my ($a, $b, $r) = ("(?<$token>", ')', undef);
In this case $token is some word (param name). This code used in functon for creating regular expression. Sample result for /users/:id is:
/users/(?<id>[^/]+?)(?:\.[^.]+?)?
I dont understand what does its mean: (?<id> ?
I know positive and negative look-behind - (?<= and (?<!. But i don`t know this.

Related

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.

How can I remove a certain pattern from a string? [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I have this string like "682_2, 682_3, 682_4". (682 is a random number)
How can i get this string "2, 3, 4" using regex and ruby?
You can do this in ruby
input="682_2, 682_3, 682_4"
output = input.gsub(/\d+_/,"")
puts output
A simple regex could be
/_([0-9]+)$/ and in the match group of the result you will have 2 for 682_2 and 3 for 682_3
Ruby code snippet would be "64532_2".match(/_([0-9]+)/).captures[0]
you can use scan which returns an array containing the matches:
string_code.scan(/(?<=_)\d/)
(?<=_) tells to find a pattern that has a given pattern (_ in this case) before itself but wont capture that, it captures only \d. if it can have more than 1 digit like 682_13,682_33 then \d+ is necessary.

notepad++ REGEX how to find matched string and keep it (delete all surrounding text) [duplicate]

This question already has answers here:
Delete all content but keeping matched
(1 answer)
Can't use ^ to say "all but"
(4 answers)
Closed 2 years ago.
I am trying to use regex function to find the following string AAA and delete everything else (except the ending part of this string)
Example:
eenqowtnorynwny55w4oynw AAABBB ewtenoqtn3oyn AAACCC 4et3o4ny3ny AAADDD 3to3n4yon45yo
wetn3o4tn3o5yn AAAZZZ wn3otn3on AAANNN
expected outpout
AAABBB
AAACCC
AAADDD
AAAZZZ
AAANNN

How to get values inside of brackets according to BODMAS rule [duplicate]

This question already has answers here:
PHP regular expression to replace nested () with []
(5 answers)
Closed 4 years ago.
I tried and stuck to this formula which only only work on 1 pair of brackets:
preg_match('#\((.*?)\)#', $text, $match);
print $match[1];
What I want to do is parse the text after the last open parenthesis before the first close parenthesis.
For example, I have equation like this:
1+(2+(3+(5-6)))+(7-8)
The text that would be parsed is "5-6".
Match ( > anything except ( or ) > )
$text = '1+(2+(3+(5-6)))+(7-8)';
preg_match('/\(([^\(\)]+)\)/', $text, $match);
var_dump($match);

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.