Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 2
    For the PCRE, I'd use 'Icecream\S+' for some non-blank characters. Commented Jun 8, 2018 at 20:19
  • Thanks for your comments, saddly it seems that my version of grep does not support perl regex. Could you add some more details about your third option? I am not quite sure how to implement it. Commented Jun 8, 2018 at 21:54
  • After some more testing it seems that using either echo "$string" | grep -oP 'Icecream.*?\b' or 'Icecream\S+' it does the job. Thanks Commented Jun 8, 2018 at 22:09
  • it's really confusing that although your $string variable is a string you still have to put it between double quotes! Commented Jun 8, 2018 at 22:10
  • @Sonamor in this case the quoting is not strictly necessary; however there are so many cases where it is that it's a good habit to get into. See for example When is double-quoting necessary? Commented Jun 8, 2018 at 23:09