Reputation: 2720
this code on java/android work fine to find all texts between <tag>
and </tag>
whats equivalent of my code on java on nodejs/javascript?
private static final Pattern TAG_REGEX = Pattern.compile("<tag>(.+?)</tag>");
private void getTagValues(final String str) {
final Matcher matcher = TAG_REGEX.matcher(str);
while (matcher.find()) {
// print found text
}
}
for example:
var value = "<tag>text 1</tag> aaaaa <tag>text 2</tag>";
var regex = '<tag>(.+?)</tag>';
var match = regex.test(value);
while (matcher.find()) {
if (match) {
console.log(value + 'is not a number that has between 1,20 digits');
}
}
Upvotes: 0
Views: 407
Reputation: 1448
I changed your code try this.This code is working as your expectations.Hope this helps for you.
var express=require('express');
var app=express();
app.get('/tag',function(request,response)
{
var value="<tag>text 1</tag>,aaaaa<tag>text 2</tag>.";
var regex="<tag>(.+?)</tag>.";
var result=value.match(/<tag>(.*?)<\/tag>/g).map(function(val){
var first=val.replace(/<\/?tag>/g,'');
console.log(first);
});
var match=regex.match(/<tag>(.*?)<\/tag>/g).map(function(valy){
var second=valy.replace(/<\/?tag>/g,'');
console.log(second);
});
response.send("data send");
});
app.listen(3000,function(){
console.log("Server is listening on http://localhost:3000");
});
See output in a browser as localhost:3000/tag
and see the text between tags in terminal.
Upvotes: 1