php - RegExp extract minecraft mod's name -


[17] => link_info-mc1.7.10-0.3.1.litemod [18] => mantle-1.7.10-0.3.2.jar [19] => micdoodlecore-1.7-3.0.11.333.jar [20] => minetweaker3-1.7.10-3.0.9c.jar [21] => modtweaker 2-0.8.0.jar [22] => mousetweaks-2.4.4-mc1.7.10.jar [23] => neiintegration-mc1.7.10-1.0.9.jar [24] => notenoughitems-1.7.10-1.0.5.110-universal.jar 

i've got of these elements in php array , need extract except:

-1.7.10-1.0.5.110-universal.jar 

so tried use regular expression this:

/[\d\-|\.]*\.jar/ 

but extracts modname string example2-0.8.0.jar.

so need make more flexible.

if understand correctly, want match every filename except 1 containing 'universal'. so, can use negative lookbehind pattern this:

/[\w\d\-|\._ ]*(?:(?<!universal)(\.jar)|(\.litemod))/ 

demo: https://regex101.com/r/mi2fm8/3


in case want match name (without version number, ...) should enough:

/^[^\- ]+/ 

demo: https://regex101.com/r/mi2fm8/5


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -