RegEx Assistance. Bash on OSX
This is probably a simple question but I'm new to bash and OSX. I would like a regex expression that returns a string between two periods followed by the word LSSharedFileList开发者_高级运维.
For example "org.videolan.vlc.LSSharedFileList.plist.lockfile" would return only "vlc".
The beginning and end of the string may change but I will only ever need the text between the periods preceding "LSSharedFileList".
Any help would be much appreciated. Thanks.
$ echo org.videolan.vlc.LSSharedFileList.plist.lockfile | sed -e 's/.*\.\(..*\)\.LSSharedFileList.*/\1/'
vlc
Here's how you can do this using bash parameter expansion:
FOO="org.videolan.vlc.LSSharedFileList.plist.lockfile"
# Strip off ".LSSharedFileList" and whatever follows
BAR=${FOO%.LSSharedFileList*}
# Strip off everything from the beginning up to the first period
BAR=${BAR##*.}
echo $BAR
精彩评论