last day (15 days later) » 

1:02 PM
0
A: Regex lazy quantifier behave greedy

Avinash RajYou could try the below regex, (?!^)(\[[A-Z].*?\]\[\d+\]) DEMO

 
MOD
It does not return the value i want if there is a [ or ] in Some Text
 
could you provide all the possibilities?
 
MOD
ok i will edit my question
 
@MOD updated my answer.
 
MOD
I am sorry @Avinash Raj But your answers make me remember other possibilities. The Some Text that i want to match can be at the beginning of the line and there can be multiple Some Texts
 
1:02 PM
that's what i said before. Please post some examples for all the possible matches and also for not.
please not in the literal form it's hard to understand.
see here regex101.com/r/qI4aA6/6 it matches any number the corresponding [] if there are any number of sometext or [] present in it. THe main part in the above regex is \[[A-Z]
Hi..
 
MOD
hi
 
Could you post some ex of all the possible matches...
i'll try to help you..
 
MOD
my gaol is to match a [Some Text] with specific number. Such as i want to match the [Some Text] with number 2 between multiple [Some Text]
the number i want to match can be any number
i can match 1 or 2 or 3 etc.
 
so you want to match [sometext][2] which may be prsent inside multiple [sometext]
 
MOD
yes but it can be number 1
at the beginning
or number 3
somewhere in multiple [Some Text]
 
1:09 PM
multiple [sometext] only not multiple [sometext][number]
 
MOD
i want to match bot [Some Text][number]
both*
 
give a sample input with limited number of [sometext] ..
just want to figure it out..
 
MOD
[Some Text][1][Some Text][2][Some Text][3][Some Text][4][Some Text][5]

match just [Some Text][1] or just match [Some Text][2] or just match [Some Text][3] etc.
 
do you want multiple matches or a single match?
 
MOD
single match
think numbers as ids of [Some Text]'s
 
1:17 PM
yes, agree. So what's your expected single match output for the above input?
 
MOD
can be different i will put a number in to a variable in jquery and match the [Some Text] i want
like
var index = 5;
var regex = new RegExp("\\[Some Text\\]\\[" + index + "\\]");
regex.exec("
[Some Text][1][Some Text][2][Some Text][3][Some Text][4][Some Text][5] ");
 
so you want to match only the [sometext][number] part where the number in variable matches with the number after [sometext]
 
MOD
yes
 
finall post all the posibilities of [Some Text] block
you said sometext may occur at the middle or at the last ,,
 
MOD
or at the beginning
 
1:26 PM
you mean only the Some Text or the whole [Some Text]
you mean the input would be,
[Some Text][1][Some Text][2][Some Text][3][Some Text][4][Some Text][5]
[Some Text][1][Some Text][2][Some Text][5][Some Text][3][Some Text][4]
[Some Text][5][Some Text][1][Some Text][2][Some Text][3][Some Text][4]
 
MOD
yes
 
like this ^^^ From there you want to match the sometext number block where the number is passed through REGEXP constructor.
Am i correct?
 
MOD
yes
 
now i'm trying to match sometext number 5 in all the above inputs..
because the number we want to search for is passed by the regexp constructor.
 
MOD
yes
 
1:30 PM
you said, inside sometext block there may be any number of []. Am i corrcet?
 
MOD
yes
 
but it must be start with [Some
is this correct?
 
MOD
No it can be any text
like [adasdasd asdasd][1]
or just [asddas][1]
 
so the only clue is we know the exact number..
 
MOD
yes
 
1:34 PM
ie, number passed by regex constructor.
 
MOD
i have to go now. than you for your spending time on my question
thank*
 
bye.. let me try.
@MOD
i think i got that.
r u here?
 
 
3 hours later…
MOD
4:58 PM
still it does not match if there is ][ in Some Text
but i guess it is right
 
MOD
5:20 PM
edit your answer then i will mark correct
 

last day (15 days later) »