简体   繁体   中英

How to extract the text between (%) and (?) from a String?

I want to extract the slug between (%) and (?) from a String url?

This is the url as string.

https://xyz.page.link/product/prdt%3D29c1118b344a53949824990eec6bd267?amv=24&apn=com.example.example&ibi=com.example.example&imv=1.0.1&isi=1613285148&link=https%3A%2F%2Fxyz.page.link%2F

I want to extract the string between % and? from this part prdt%3D29c1118b344a53949824990eec6bd267?

Is that possible?

Thanks

Yes you can use RegExp class.

Please take a look at this answer: How to use RegEx in Dart?

void main() {
    var a ='https://xyz.page.link/product/prdt%3D29c1118b344a53949824990eec6bd267?amv=24&apn=com.example.example&ibi=com.example.example&imv=1.0.1&isi=1613285148&link=https%3A%2F%2Fxyz.page.link%2F';
    var regexp = RegExp(r"(?<=\%).+?(?=\?)");
    print(regexp.hasMatch(a)); // true
    print(regexp.firstMatch(a)?.group(0)); // 3D29c1118b344a53949824990eec6bd267
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM