'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



Solution 1:[1]

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
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ethicnology