在反应中显示字符串中两个子字符串之间的所有出现
Display all occurrences between two substrings within a string in react
我正在尝试直接从 div 中提取信息,其中有超过 25 页的重复信息。例如,信息看起来像这样:
var first = "Your Name is: name Your Age is: age Your email is: email....Your Name is: name Your Age is: age Your email is: email....Your Name is: name Your Age is: age Your email is: email....Your Name is: name Your Age is: age Your email is: email....Your Name is: name Your Age is: age Your email is: email...."
我想提取“你的名字是:”和“你的年龄是:”之间多次出现的子字符串,以及年龄、电子邮件。
var name = "Your Name is:"
var age = "Your Age is:"
var re = new RegExp(name,'gi');
var re2 = new RegExp(age,'gi');
var result = new Array();
while (re.exec(first){
results.push(re.lastIndex);}
var result2 = new Array();
while (re2.exec(first){
results.push(re2.lastIndex);}
var info = first.substring(
first.lastIndexOf(name) + 1,
first.lastIndexOf(age)
);
<span>{info}</span>
我希望信息循环并一次显示所有值。
帮助。
由于数据已更改,我更新了我的答案...
如果是我,我会用“你的名字是:”拆分 DIV 文本,然后 运行 这个正则表达式
^([\w ]+).*? Your Age is: (\d+).*?email is: ([\w@].*?) Your
对于每一行,它会拉取你想要的数据。
查看它在 regex101.com 上的工作情况。
如果您不想或不能先拆分字符串,您将对电子邮件部分感兴趣以实际接收电子邮件。有关示例,请参阅 this question。
我正在尝试直接从 div 中提取信息,其中有超过 25 页的重复信息。例如,信息看起来像这样:
var first = "Your Name is: name Your Age is: age Your email is: email....Your Name is: name Your Age is: age Your email is: email....Your Name is: name Your Age is: age Your email is: email....Your Name is: name Your Age is: age Your email is: email....Your Name is: name Your Age is: age Your email is: email...."
我想提取“你的名字是:”和“你的年龄是:”之间多次出现的子字符串,以及年龄、电子邮件。
var name = "Your Name is:"
var age = "Your Age is:"
var re = new RegExp(name,'gi');
var re2 = new RegExp(age,'gi');
var result = new Array();
while (re.exec(first){
results.push(re.lastIndex);}
var result2 = new Array();
while (re2.exec(first){
results.push(re2.lastIndex);}
var info = first.substring(
first.lastIndexOf(name) + 1,
first.lastIndexOf(age)
);
<span>{info}</span>
我希望信息循环并一次显示所有值。 帮助。
由于数据已更改,我更新了我的答案...
如果是我,我会用“你的名字是:”拆分 DIV 文本,然后 运行 这个正则表达式
^([\w ]+).*? Your Age is: (\d+).*?email is: ([\w@].*?) Your
对于每一行,它会拉取你想要的数据。
查看它在 regex101.com 上的工作情况。
如果您不想或不能先拆分字符串,您将对电子邮件部分感兴趣以实际接收电子邮件。有关示例,请参阅 this question。