The problem of string segmentation and extraction

excuse me, there is a string as follows, with the offline at the beginning and the mysql.dba.com.lan at the end. It will not change, but the xxx.yyy.zzz in the middle is uncertain. How to intercept the xxx.yyy.zzz, no matter whether the middle part is xxx, xxx.yyy or xxx.yyy.zzz

offline.xxx.yyy.zzz.mysql.dba.com.lan.
Jun.16,2022

if '.mysql.dba.com.lan.' exists in the middle. String, str.replace ('offline.',') .replace ('.mysql.dba.com.lan.,') this method will have a problem.

the same problem exists with the clumsy method, which is changed to str.substring (8 grade str.lastIndexOf ('.mysql.dba.com.lan.)) Just do it.

regular spicy is still great.


regular is the most convenient

'offline.xxx.yyy.zzz.mysql.dba.com.lan.'.match(/offline\.(.+)\.mysql\.dba\.com\.lan\./)

var res = str.replace ('offline.',''). Replace ('.mysql.dba.com.lan.,')


regular is not very good, use stupid method

var str = "offline.xxx.yyy.mysql.dba.com.lan.";
var result = str.substring(8,str.indexOf('.mysql.dba.com.lan.'))
console.log(result) // xxx.yyy
Menu