Hello, help to make regular. There is a line, if in a line, for example, there is 453 | 571 then take everything up to "" (space)

var str = '461|572|0|4|29|29|7809169 453|571|0|2|66|66|7809053 446|565|0|4|41|41|7809052'; if(str.indexOf('453|571')>=0){ var res = str.match('регулярочка'); console.log('453|571|0|2|66|66|7809053'); } 

Closed due to the fact that off-topic participants Wiktor Stribiżew , αλεχολυτ , Cheg , user207618, Lex Hobbit August 14 '17 at 1:26 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The message contains only the text of the task, in which there is no description of the problem, or the question is purely formal (" how do I do this task ") . To reopen the question, add a description of the specific problem, explain what does not work, what you see the problem. " - αλεχολυτ, Cheg, Community Spirit, Lex Hobbit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • (^| )([^ ]*453[|]571[^ ]*)($| ) - Akina
  • @Akina thanks!) - Mikhail Petrov

1 answer 1

And what prevents to use split?

 var str = '461|572|0|4|29|29|7809169 453|571|0|2|66|66|7809053 446|565|0|4|41|41|7809052'; if(str.indexOf('453|571')>=0){ var res = str.split(' '); console.log(res[1]); } 

  • And if "453 | 571" is not after the first space? - br3t
  • I don't have much experience in js. But it seems to me that through the split will be more gluttonous. because need to iterate over all array values? I found only $ .isArray in the documentation, but it only returns an index, but I need a value - Mikhail Petrov