Home > Blockchain >  Regex to find Text between different chars
Regex to find Text between different chars

Time:10-26

Im looking for a fast way to get a word in a huge text which starts with "TEST-"

Lorem ipsum dolor sit amet, consectetur adipisici elit "TEST-12345" Lorem ipsum dolor sit amet, consectetur adipisici elit 'TEST-12345' Lorem ipsum dolor sit amet, consectetur adipisici elit " TEST-12345 " Lorem ipsum dolor sit amet, consectetur adipisici elit "TEST-12345" sed diam nonumy eirmod tempor invidunt Lorem ipsum dolor sit amet, consectetur adipisici elit " TEST-12345 "

I have tried to archive this with different loops, but im getting Unexpected identifier everytime

Lorem ipsum dolor sit amet, consectetur adipisici elit "TEST-12345" Lorem ipsum dolor sit amet, consectetur adipisici elit 'TEST-12345' Lorem ipsum dolor sit amet, consectetur adipisici elit " TEST-12345 " Lorem ipsum dolor sit amet, consectetur adipisici elit "TEST-12345" sed diam nonumy eirmod tempor invidunt Lorem ipsum dolor sit amet, consectetur adipisici elit " TEST-12345 "

var text = 'Lorem ipsum dolor sit amet, consectetur adipisici elit "TEST-12345"\
Lorem ipsum dolor sit amet, consectetur adipisici elit \'TEST-12345\'\
Lorem ipsum dolor sit amet, consectetur adipisici elit " TEST-12345 "\
Lorem ipsum dolor sit amet, consectetur adipisici elit "TEST-12345" sed diam nonumy eirmod tempor invidunt\
Lorem ipsum dolor sit amet, consectetur adipisici elit " TEST-12345 "'.split("\\")
for (var x in text) {
    console.log(text[x])
}

CodePudding user response:

Use .match method.

text.match(/TEST-\d{5}/g)
  • Related