Skip to content
Advertisement

Preg_Mach_All How To Eliminate the Ending Characters

I love preg_mach_all command, but now I have this situation:

$lotes_fil='/((?:https?|http?)://(?:S*?.S*?)(?:[s)[]{};"'<]|.s|$))/';

preg_match_all($lotes_fil,$rs,$link_pre, PREG_SET_ORDER);

The output is this:

[0] => Array
    (
        [0] => https://s3.amazonaws.com/mesena.com/vodcategories/58e1a299dca3c3a22fbd8319/iconPng-1576021669572.png"
        [1] => https://s3.amazonaws.com/mesena.com/vodcategories/58e1a299dca3c3a22fbd8319/iconPng-1576021669572.png"
    )

[1] => Array
    (
        [0] => https://images.mesena.com/assets/images/default/vodcategory.id-imageFeatured.jpg"
        [1] => https://images.mesena.com/assets/images/default/vodcategory.id-imageFeatured.jpg"
    )

[2] => Array
    (
        [0] => https://s3.amazonaws.com/silo.mesena.com/origin/5638f208fbdc021398ae8681/production/202006/19/5638f208fbdc021398ae8681_212-21719"
        [1] => https://s3.amazonaws.com/silo.mesena.com/origin/5638f208fbdc021398ae8681/production/202006/19/5638f208fbdc021398ae8681_212-21719"
    )

I need eliminate the last but i want use this regex beacuse working for me well.In the original data have as the ending for each URL

Thx for your help.

Advertisement

Answer

I’d use:

~https?://[^s"]+~ 

Explanation:

~       # regex delimiter, it allows to use / without escaping
https?    # http OR https
://       # literally
[^s"]+   # 1 or more any character that is not a space or double quote
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement